I have a bunch of ElementHosts that I\'m loading onto my form. When this happens, the element hosts all appear with a black background. If I bring another control to front,
Holy sh*t, I finally got it working. I tried this code from Google (there were a couple of sources.... How do I suspend painting for a control and its children? ...to name one):
private const int WM_SETREDRAW = 0x000B;
public static void Suspend(this Control control)
{
Message msgSuspendUpdate = Message.Create(control.Handle, WM_SETREDRAW, IntPtr.Zero,
IntPtr.Zero);
NativeWindow window = NativeWindow.FromHandle(control.Handle);
window.DefWndProc(ref msgSuspendUpdate);
}
public static void Resume(this Control control)
{
var wparam = new IntPtr(1);
Message msgResumeUpdate = Message.Create(control.Handle, WM_SETREDRAW, wparam,
IntPtr.Zero);
NativeWindow window = NativeWindow.FromHandle(control.Handle);
window.DefWndProc(ref msgResumeUpdate);
control.Invalidate();
}
It didn't solve my problem and left me with the black messed up backgrounds...BUT I thought to try adding the following to the Resume method:
public static void Resume(this Control control)
{
control.Visible = false;
// existing code above....
control.Visible = true;
}
and BAM!!! it works.
Although not being a direct answer to your problem, have you tried to add just one ElementHost (and hence just one WPF UserControl) to your WindowsForm.
You might achieve this if you create a WPF UserControl which aggregates all your individual WPF UserControl. Is this a viable solution for you? t might reduve Or do you have to mix windows forms controls with wpf ones?