数据绑定是否始终编组到 UI 线程?
当绑定到 Silverlight 3 和 4 中的属性时,Windows Phone 7 版本 silverlight 以及 WPF 3.5 和 4 中的属性更改通知是否始终编组到 UI 线程?您是否知道我不能依赖它并且必须在我的代码中进行编组的任何情况?
When binding to a property in Silverlight 3 and 4, the Windows Phone 7 version silverlight and in WPF 3.5 and 4 will property change notifications always be marshalled to the UI thread? Are you aware of any scenario where I can not rely on that and would have to do the marshalling in my code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我做了一些实验...
INotifyPropertyChanged
如果您从后台线程对属性进行更改,并且它从该后台线程触发 INotifyPropertyChanged,并且该属性是数据绑定的,那么...
依赖属性
如果该属性是依赖属性而不是 INotifyPropertyChanged 怎么办?如果您从后台线程更改此属性会怎样?好吧,我没有做过任何实验,但我读到它没有进行任何编组。
INotifyCollectionChanged(例如 ObservableCollection)
如果您从后台线程添加/删除 ObservableCollection 中的元素,并且该集合通过数据绑定到列表框或类似内容,那么会发生什么?
I did some experiments...
INotifyPropertyChanged
If you make a change to a property from a background thread, and it fires INotifyPropertyChanged from that background thread, and the property is databound, then...
DependencyProperty
What if the property is a dependency property rather than INotifyPropertyChanged? What if you alter this property from a background thread? Well, I haven't done any experiments, but I read that it doesn't do any marshalling.
INotifyCollectionChanged (e.g. ObservableCollection)
If you add/remove elements in an ObservableCollection from a background thread, and the collection is databound to a listbox or similar, then what happens?
是的,收藏。当您绑定到可观察集合并从非 UI 线程更改它时,您将收到异常。您必须将集合更改编组到 UI 线程。
Yes, collections. When you bind to an observable collection and you change it from a non-UI thread you will get an exception. You will have to marshal the collection change to the UI thread.