UI 刷新在绘制时冻结应用程序

发布于 2024-12-03 04:12:56 字数 348 浏览 2 评论 0原文

这是一个推测性问题,因此没有提供代码。

我有一个应用程序,它采用一个大型 XML 文件并从中构建一个视图以供用户编辑。 XML 的加载在后台工作程序中执行,然后通过树视图以相当普通的 MVVM 方式绑定到视图。

这一切都运行得很好,并且在工作人员加载 XML 时会显示一个漂亮的等待光标。

然而,当 XML 文件变得非常大(20M)时,UI 将在绘制新视图期间挂起。这是可以预料的,但这确实意味着应用程序仍然存在的所有视觉提示也会冻结。目前,一旦工人在油漆之前完成加载,光标就会发生变化。是否有一个“paintingHasFinished”类型事件用于控件或漂亮的技巧,我可以将其用作句柄,以便我可以在此 UI 操作之后更改等待光标?

This is a speculative question so no code provided.

I have an application that takes a large XML file and builds a view from this for editing by the user. The loading of the XML is carried out in a background worker and is then bound to the view in a pretty vanilla MVVM way via a tree view.

This all works very well and a nice wait cursor is shown while the worker loads the XML.

However when the XML file gets very big (20M) the UI will hang during the painting of the new view. This is to be expected, but it does mean all of the visual cues that the app is still alive, freeze as well. At the moment the cursor is changed once the loading has finished in the worker just before the paint. Is there a 'paintingHasFinished' type event for a control or nifty trick that I could use as a handle so I can change my waiting cursor after this UI action?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱你是孤单的心事 2024-12-10 04:12:56

您可以使用调度程序了解视图何时完成渲染。

尝试添加以下内容:

this.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(() =>
    {
        Cursor = Cursors.Arrow;
    }
));

这会挂钩到调度程序,要求它在加载完成后使用异步调用调用回调。提供的匿名操作将被调用,并且应该将光标设置回正常状态。

You can find out when a View has finished being rendered by using the Dispatcher.

Try adding this:

this.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(() =>
    {
        Cursor = Cursors.Arrow;
    }
));

This hooks into the dispatcher, asking it to call the callback when it's done loading, using an asynchronous call. The provided anonymous Action will get called and should set your cursor back to normal.

初雪 2024-12-10 04:12:56

您可以使用调度程序逐一或批量添加您创建的 ViewModel,以便逐渐添加项目,并且在加载操作结束时不会使测量/布局线程过载。这将增加总体加载时间,但也会增加用户体验。

还要确保虚拟化已打开(虚拟化堆栈面板或数据网格上的列/行虚拟化),这将显着提高大型数据集的性能。

You could add the ViewModels you create one by one or in batches of x, using the dispatcher, so that the items get added gradually and will not overload the measure/layout thread at the end of the load operation. This will increase overall load time but also increase user experience.

Also make sure virtualization is turned on (virtualizing stack panel or column/row virtualization on a datagrid), this will significantly improve performance with large data sets.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文