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

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强制刷新界面

上一篇:(转)js弹窗&返回值(window.open方式)


下一篇:WPF 设置程序不允许多开