views:

719

answers:

3

I have a Winform that uses an ElementHost to display a WPF UserControl. Once every 50 times or so when the form loads the WPF content fails to paint. You can see through the Winform chrome to whatever is beneath. Resizing the window gets the WPF content to show up.

Is this a known issue? Can anyone suggest a workaround?

Thanks Scott

A: 

Maybe call Invalidate on the ElementHost?

casperOne
This did not work for us. See my answer.
cplotts
+2  A: 

We have fought these types of issues before. See this WPF forum post for more info on our particular flavor (I don't know if it is the same issue or not).

The only thing that we found to work was to change the size of the ElementHost.

_elementHost.Width++;

It's a complete hack, ugly, and I'm embarrassed to even post it. But nothing else ever worked for us. So, it is definitely a workaround. (Grin)

We tried Invalidate, Refresh and everything we could think of ... on the ElementHost. We also tried InvalidateMeasure, InvalidateArrange, and InvalidateVisual on the WPF hosted content. No luck.

If you find another way to fix your issue, I would love to hear about it.

Good luck, I know I have lost some hair on this one.

Update 1: I have submitted another WPF forum post on this. Maybe we can get a response from Microsoft. Sure seems like a bug to me.

Update 2: After I fixed the refresh issue with the above hack ... I still had another problem to solve that I thought worth mentioning here. That is: there was a definite delay until the screen refreshed. This made it seem like the user was navigating to another screen (it wasn't ... it was just the contents of the double buffering buffer). I ended up having to manually call System.Windows.Forms.Control.Refresh() on the Control that was hosting the ElementHost. In this way, even though the pause was still there ... at least the screen was blank ... and it didn't look like the user was navigating somewhere ...

cplotts
Thanks for the input, we ended up doing a similar and equally ugly hack
Thanks summergoat. As you can see in my updated answer, I have submitted another WPF forum post. We'll see if anything comes from that.
cplotts
A: 

Have you tried to use reflection to see the code behind _elementHost.Width++?

Captain
I have used .NET Reflector to take a look at the code behind ElementHost, and actually there seems to be a lot of knobs to tinker with. Unfortunately, I've already spent too much time on this issue. However, the Width property is actually implemented on the base class. No help there.
cplotts