读书人

wpf中相仿redrawWindow函数

发布时间: 2013-01-05 15:20:39 作者: rapoo

wpf中类似redrawWindow函数?
自定义一个控件,此控件需要每0.01s刷新一次,
我试着用DispatcherTimer类来刷新,在刷新时调用InvalidateVisual函数,让它可以调用OnRender重绘。

用Debug输出调试信息,刷新一次后,InvalidateVisual调用多次,OnRender才一次,
所以认为是InvalidateVisual没有立即重绘,导致没有正确绘制出需要的效果。

请问各位有没有其他的好的办法?
[解决办法]
有关InvlidateVisual,MSDN上有介绍:
This method is not generally called from your application code. The WPF framework-level layout system does its own handling of changes in the visual tree of an element, and would be calling the equivalent of this method when necessary already. Calling this method is necessary only for advanced scenarios. One such advanced scenario is if you are creating a PropertyChangedCallback for a dependency property that is not on a Freezable or FrameworkElement derived class that still influences the layout when it changes.
不知道你的控件是不是符合这样的情况

[解决办法]
vc++实现的

读书人网 >.NET

热点推荐