首页 > Windows开发 > 详细

【转】【WPF】WPF强制刷新界面

时间:2021-08-11 19:17:07      阅读:15      评论:0      收藏:0      [点我收藏+]

Winform 里有 Application.DoEvents();可刷新!

WPF 里没这个,尽管可用委托实现多线程,但是刷新还是不行!

后来找到了 类似App.DoEvents()的方法();

代码:

public partial class App : Application
    {
        private static DispatcherOperationCallback exitFrameCallback = new DispatcherOperationCallback(ExitFrame);
        public static void DoEvents()
        {
            DispatcherFrame nestedFrame = new DispatcherFrame();
            DispatcherOperation exitOperation =  Dispatcher.CurrentDispatcher.BeginInvoke (DispatcherPriority.Background, exitFrameCallback, nestedFrame);
            Dispatcher.PushFrame(nestedFrame);
            if (exitOperation.Status !=
            DispatcherOperationStatus.Completed)
            {
                exitOperation.Abort();
            }
        }

        private static Object ExitFrame (Object state)
        {
            DispatcherFrame frame = state as
            DispatcherFrame;
            frame.Continue = false;
            return null;
        }

    }

}

 

原文地址:https://www.cnblogs.com/FengShenMeng/p/6054571.html

 

【转】【WPF】WPF强制刷新界面

原文:https://www.cnblogs.com/mqxs/p/15128737.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!