简体   繁体   English

可见时如何重绘WinFormsHost?

[英]How to repaint a WinFormsHost when it becomes visible?

I've a winforms control within a WindowsFormsHost on a WPF control. 我在WPF控件的WindowsFormsHost中有一个winforms控件。 The WPF control is only visible some of the time, and when it becomes visible the contents of the winforms control have usually changed. WPF控件仅在某些时间可见,当它可见时,winforms控件的内容通常已更改。

When the ViewModel for the WPF control changes I change the contents of the winforms control and the WPF control becomes visible. 当WPF控件的ViewModel更改时,我更改了winforms控件的内容,并且WPF控件变为可见。

Unfortunately, the previous contents of the winforms control is repainted, as if from a visual cache. 不幸的是,winforms控件的先前内容被重新绘制,就好像是从视觉缓存中一样。 I've run it through the debugger and I know that the winforms control is having its data updated, but it won't repaint until I re-size the program window (when a repaint is clearly triggered). 我已经通过调试器运行它,而且我知道winforms控件正在更新其数据,但是直到我重新调整程序窗口的大小(明显触发了重新绘制)之后,它才会重新绘制。

I've tried Invalidate() on the winforms control and InvalidateVisual(), InvalidateArrange() and InvalidateMeasure() on the WPF control inside the DataContextChanged event handler for the WPF control, but it seems that because the WPF control is not visible at this point (it's just about to become visible) these method calls are swallowed. 我已经在WPF控件的DataContextChanged事件处理程序中的Winforms控件上尝试了Invalidate(),并在WPF控件上尝试了InvalidateVisual(),InvalidateArrange()和InvalidateMeasure(),但是似乎因为WPF控件在此不可见点(即将变得可见),这些方法调用将被吞没。

Anyone got any clever ideas on how to force a repaint of a WinFormsHost-ed winforms control immediately after the hosting WPF control becomes visible? 任何人都知道如何在托管WPF控件可见后立即强制重绘WinFormsHost-ed winforms控件?

您是否尝试使IsVisibleChanged事件处理程序中的WinForms控件无效?

You should be able to call Refresh() on the hosted Control as soon as you make it visible. 使其可见后,您应该能够在托管的控件上调用Refresh() Refresh() , as per the documentation: 根据文档Refresh()

Forces the control to invalidate its client area and immediately redraw itself and any child controls. 强制控件使它的客户区无效,并立即重绘自身和所有子控件。

This turned out to be due to the underlying data-structure failing to notify that it had changed - nothing to do with the paint methods at all! 事实证明这是由于基础数据结构无法通知其已更改-与paint方法完全无关! :( Thanks for your help guys. :(感谢您的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM