vrijdag 22 juli 2011

WindowsFormsHost on a transparent WPF window

When you create a fancy WPF window with AllowTransparency set to true, all WindowsFormsHost controls  will be invisible because of some underlaying incompatible drawing methods.

This issue also causes the WPF WebBrowser control to be invisible on transparent windows. Chango V. has worked out a solution which creates an overlay for the WebBrower. I've created a similar solution for the WindowsFormsHost control. We make use of a separate non-transparent window which overlays a target FrameworkElement in the transparent window.

It seem to work fine, so I want to share it with the world. Here is the sourcecode:

WindowsFormsHostOverlay.xaml


WindowsFormsHostOverlay.xaml.cs


Here is a small (and incomplete) example of how you use WindowsFormsHostOverlay:

XAML


CS