等待控件完成渲染/重新绘制

时间:2019-03-29 22:38:22

标签: c# wpf

我正在尝试实施此问题的注释中提到的解决方案:

Rendering part of large Visual object performance

该解决方案并非恰恰是我想要的(如果您知道此事,请随时帮助我解决其他问题)。但这应作为解决当前问题的一种快速解决方法。

我已经实现了它,它显然要快得多,并让我可以使用其他非UI并行线程进行处理。 问题是 ...为了使该解决方案有效,我必须在整个图形上“滚动”以提取其所有“块”,然后再将它们合并在一起。。< / p>

我用于执行此操作的(外部)控件具有一个名为TranslateX(或Y)的属性,可用于导航。

我遇到的问题是,如果仅调用其属性,我仍然需要稍等片刻,以使更改显示在屏幕上。而且我找不到一种方法告诉方法“等到缩放控件完成绘制”。

很明显,如果我在捕获屏幕之前放置Task.Delay(x),则它“有效”。但是出于明显的原因,这不是我想要使用它的方式,特别是考虑到图形较大的UI需要较长的渲染时间。

我尝试过的东西

  • 我尝试先“ InvalidateLayout”然后“ UpdateLayout”
  • 尝试使用以下代码段对我不起作用:

    await zoom.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.SystemIdle, new Action(() => { }));
    

(我尝试通过使用Invoke和BeginInvoke更改DispatcherPriority)

代码段

//Note: Zoom is the control I'm using to move around the canvas that contains the graph

zoom. TranslateX += zoomArea.Width;
//Desperation trying to figure out if any of these work.... No, they don't
zoom.InvalidateArrange();
zoom.InvalidateVisual();
zoom.UpdateLayout();

//Small delay thinking that the UI thread might need to wait a bit before the next line actually works... it does nothing
await Task.Delay(1);
//Code I found that should make the Dispatcher to run the (empty) action when the dispatcher finished rendering, does not work
await zoom.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.SystemIdle, new Action(() => { }));
//The actual code that captures the screen
Bitmap theImage = await Task.Run(() => Capture(windowDC, zoomArea));
//keep working...

感谢您能提供的任何帮助。谢谢!

0 个答案:

没有答案