WPF NotifyPropertyChangeds 是否已编组到调度程序?
如果我更新一个在绑定控件的调度程序之外的线程上抛出 NotifyPropertyChanged 的属性,更新会被强制编组到该调度程序吗?
BackgrounWorker.Run() => { blah.Blahness = 2; // notifies property changed on BW, is this marshalled to the dispatcher? }
If I update a property that throws a NotifyPropertyChanged on a thread other than the bound control's dispatcher is the update forcibly marshalled to this dispatcher?
BackgrounWorker.Run() => { blah.Blahness = 2; // notifies property changed on BW, is this marshalled to the dispatcher? }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,
PropertyChanged
事件会自动编组到 UI 调度程序,因此您无需使用Invoke
显式编组它。请注意,它仅适用于标量属性的更改通知(即
PropertyChanged
事件)。集合更改通知(INotifyCollectionChanged.CollectionChanged
事件)不会以这种方式工作,它们必须在 UI 线程上手动引发。我编写了一个自动执行此操作的类,您可以找到它 此处。Yes, the
PropertyChanged
event is automatically marshalled to the UI dispatcher, so you don't need to useInvoke
to marshall it explicitly.Note that it is only true for change notifications on scalar properties (i.e.
PropertyChanged
event). Collection change notifications (INotifyCollectionChanged.CollectionChanged
event) don't work that way, they must be raised on the UI thread manually. I wrote a class that does it automatically, you can find it here.