Saturday, November 27, 2010

WPF and Winforms “airspace problem”: a solution

In a previous post, I talked about the “airspace problem”, an issue you can encounter when you are using WPF and WinForms in the same application. I created a small sample application that shows the issue and I’ve also added a possible solution.

If you run the application, you’ll see the following user interface:

image

This userinterface contains the following important elements:

  • A WPF Grid control that is not visible by default
  • A WPF button
  • A WindowsFormsHost control containing a usercontrol with a calendar control inside

When you click the button, the WPF Grid will be made visible. You see that the winformshost control is still shown on top of the grid(recognizable by the brown border on the left and the bottom.

image

Now try again but first select the Solve Airspace problem checkbox. This time the control is correctly shown on top of the winformshost.

image

Download the code and the sample application here.

1 comment:

Simon said...

The title promises more than meets the program. You should mention that the calendar is displayed only as a static bitmap behind the brown rectangle. The calendar is no longer usable. Thanks anyway for the source code.