简体   繁体   English

如何在WPF表单中显示渲染状态?

[英]How to display render status in a WPF form?

I'm overriding WPF's OnRender to draw complex graphics. 我重写WPF的OnRender来绘制复杂的图形。 This may rarely take a long time. 这可能很少会花费很长时间。 I would like to indicate to the user that the app did not crash, but is "merely" taking a long time to render. 我想向用户表明该应用程序没有崩溃,但是“仅仅是”需要很长时间才能呈现。

How would I do that? 我该怎么做? It seems not possible to modify the UI in any way during the OnRender call. 在OnRender调用期间,似乎无法以任何方式修改UI。

You are talking about placing a "Busy Indicator" on top of your drawing. 您正在谈论在图形上方放置“忙碌指示器”。

Just place a half transparent grid on top with the writing "Loading..." and you're done. 只需在上面放一个半透明的网格,上面写上“正在加载...”,就可以完成。

Bind its visibility to some bool that you update once when entering the complex rendering, and once when finished. 将其可见性绑定到在输入复杂渲染时一次更新,在完成时一次更新的布尔。

Or put a spinning Ellipse with gradient background if you want to see motion.. 或者,如果您想看运动,可以放一个带有渐变背景的旋转椭圆。

Since the OnRender method will execute on the UI thread you cannot do anything else such as displaying an interactive ProgressBar or respond to user input during the execution of your code. 由于OnRender方法将在UI线程上执行,因此您无法执行其他任何操作,例如显示交互式ProgressBar或在执行代码期间响应用户输入。

What you can do is to pop up a new window that launches in a separate thread and display this one right before you begin to draw your complex graphics. 您可以做的是弹出一个新窗口,该窗口在单独的线程中启动,并在开始绘制复杂图形之前立即显示此窗口。

Please refer to my answer in the following similar question for more information about this. 有关此的更多信息,请参考以下类似问题中的回答。

Wait screen during rendering UIElement in WPF 在WPF中渲染UIElement期间的等待屏幕

Once the OnRender method has returned you then close the temporary "loading" window: 一旦OnRender方法返回,您就可以关闭临时的“加载”窗口:

Can I stop WPF from executing UI actions out of the order in my code 我可以停止WPF从我的代码中按顺序执行UI动作吗

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

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