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

7 opmerkingen:

  1. Great!

    Is it OK to use this code in my application?

    Best regards Peter

    BeantwoordenVerwijderen
  2. Great you like it :-)

    You can use the code any way you want.

    BeantwoordenVerwijderen
  3. hi
    Owner = Window.GetWindow(t); in error

    Cannot set Owner property to a Window that has not been shown previously.

    BeantwoordenVerwijderen
  4. Yasin, errordescription is selfexplaining...
    Show the target window prior construction the WindowsFormsHostOverlay.

    BeantwoordenVerwijderen
  5. Can you sent project to mail - flai@bigmir.net?

    BeantwoordenVerwijderen
  6. I've been using this in a large project which I can't send. I don't have a small testproject for this.

    But you should get it running with the provided code.

    BeantwoordenVerwijderen
  7. Holy moly! This is great! I've been using it to host stupid ActiveX-Controls and it works tremendously good.

    Thanks a lot Maarten!

    BeantwoordenVerwijderen