在 WPF 中,是否有“渲染完成"?事件? [英] In WPF, is there a "render complete" event?

查看:43
本文介绍了在 WPF 中,是否有“渲染完成"?事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 WPF 中,当我加载包含大量元素的环绕面板时,窗口会在显示内容之前暂停一段时间.我想添加一个等待提示,但我找不到检测包装面板何时完成渲染的方法.

In WPF, When I load a wrap panel with a lot of elements, the window stalls for a while before showing the content. I would like to add a wait hint but I could not find a way to detect when the wrap panel completes rendering.

我尝试过加载"、大小改变"、初始化",但都没有成功.有没有人对这个问题有任何想法?

I have tried "loaded", "sizechanged", "initialized" without success. Has anyone got any idea on this issue ?

非常感谢!

推荐答案

我现在知道这个问题有点老了,但我刚刚遇到了同样的问题并找到了一个很好的解决方案,并认为这可以帮助其他人在将来.在渲染开始时调用 Dispatcher.BeginInvoke 和 ContextIdle 的 Dispatcher Priority.我的渲染开始恰好是一个树视图选定项更改事件,但这可能是您需要等待 UI 完成更新的任何事件.

I know at this point this question is a little old, but I just ran into this same issue and found a great work around and figured this could help someone else in the future. At the start of rendering call Dispatcher.BeginInvoke with the Dispatcher Priority of ContextIdle. My start of rendering just happened to be a treeview selected item change event, but this could be any event that you need to wait for the UI to finish updating.

    private void TreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
    {
        Dispatcher.BeginInvoke(new Action(() => DoSomething()), DispatcherPriority.ContextIdle, null);
    }

    private void DoSomething()
    {
       //This will get called after the UI is complete rendering
    }

这篇关于在 WPF 中,是否有“渲染完成"?事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆