Missing WM_PAINT when hosting a WPF control inside a winforms application.
Posted
by Boris
on Stack Overflow
See other posts from Stack Overflow
or by Boris
Published on 2010-04-30T19:00:26Z
Indexed on
2010/04/30
19:07 UTC
Read the original article
Hit count: 420
Hi All,
Consider the following scenario: 1) Create a winforms application with an empty form. 2) Create a WPF usercontrol in the same project which is just the default control with background changed to blue.
<UserControl x:Class="WindowsFormsApplication2.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300" Background="Blue">
<Grid>
</Grid>
</UserControl>
3) Build the project 4) Add the control to your form (an ElementHost is added and the control is added inside it). 5) Run the application (everything looks nice) 6) Start Spy++, click find window (Control+F) and move the cursor onto the WPF control (the blue square)
Something strange happens, the control gets a WM_ERASEBKGND message but no WM_PAINT message so now it is white. You can resize the form, hide the form behind other windows and the WPF control will not get rendered.
There is an image of the scenario here: http://img260.imageshack.us/img260/2296/wmpaint.png
This is a simplified example of the situation I have in the actual application.
Please tell me what is the best way to resolve this issue such that the WPF control renders itself correctly. I would like a solution that can be incorporated into a large application with many controls on the form.
Thank you very much in advance, Boris
© Stack Overflow or respective owner