Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
355 views
in Technique[技术] by (71.8m points)

c# - Winforms WPF Interop - WPF content fails to paint

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 ...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...