需求
在当前ViewModel类中执行某种数据列表的操作,希望View中绑定的Model类随着数据列表的改表实时刷新在View的界面上,我们可以定义一个界面强制刷新的方法,每当循环操作完列表中的一条数据,即执行强制刷新方法,让界面实时展示数据的变动。
代码块
//刷新界面控件
public void Refresh()
{
DispatcherFrame frame = new DispatcherFrame();
Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background,
new DispatcherOperationCallback(delegate (object f)
{
((DispatcherFrame)f).Continue = false;
return null;
}
), frame);
Dispatcher.PushFrame(frame);
}