如果我更新的属性在绑定(bind)控件的调度程序以外的线程上抛出 NotifyPropertyChanged,更新是否会被强制编码到此调度程序?
BackgrounWorker.Run() => { blah.Blahness = 2; // notifies property changed on BW, is this marshalled to the dispatcher? }
最佳答案
是的,PropertyChanged
事件会自动编码到 UI 调度程序,因此您无需使用 Invoke
显式编码它。
请注意,它仅适用于标量属性的更改通知(即 PropertyChanged
事件)。集合更改通知(INotifyCollectionChanged.CollectionChanged
事件)不能以这种方式工作,它们必须在 UI 线程上手动引发。我写了一个自动完成的类,你可以找到它here .
关于WPF 是否将 NotifyPropertyChangeds 编码到调度程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6773908/