就在我以为我终于掌握了 WPF 更改通知的时候,Timer 的一些虫子破坏了我的幻想......
public MyModel _objectToRefresh;
public Refresher(MyModel objectToRefresh,Dispatcher dispatcher)
{
_objectToRefresh= objectToRefresh;
_objectToRefresh.DisplayMessage = "ChangeNotification works for this one!";
_timer = new DispatcherTimer(TimeSpan.FromSeconds(3),
DispatcherPriority.Background,
eh,
dispatcher);
_timer.Start();
}
private void eh(object sender, EventArgs e)
{
_objectToRefresh.DisplayMessage = "This Change will not show in the UI";
}
附带说明一下,MyModel
实现 INotifyPropertyChanged。现在,在 UI 线程上运行的 DispatcherTimer 是什么?谁能解释这里出了什么问题?