WPF-DataBinding是否支持异步更新

发布于 2024-09-14 13:52:15 字数 272 浏览 2 评论 0原文

我意外更改了从 BackgroundWorker (BackgroundWorker.DoWork) 中实现 INotifyPropertyChanged 的 BusinessObject 属性的值。

令人惊讶的是,这并没有导致错误,而是实现了绑定到属性的 TextBlock 文本,没有任何抱怨。

异步绑定的执行是 WPF 绑定引擎的一部分,还是这只是由于其他考虑而忘记或省略 CheckAccess 测试的特殊情况。

I changed accidentally the value of a BusinessObject-property that implements INotifyPropertyChanged from within a BackgroundWorker (BackgroundWorker.DoWork).

Amazingly, this led not to an error but actualized the text of the TextBlock that was bound to the property without any complaint.

Is the execution of asynchronous bindings part of the WPF binding engine or is this only a special case where the CheckAccess-test have been forgotten or ommited due to other considerations.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

相权↑美人 2024-09-21 13:52:15

标量属性上的绑定支持来自其他线程的更新,因此在更新模型(或 ViewModel)的属性时无需调用 Dispatcher.Invoke。但是,对于绑定到集合而言,情况并非如此:如果您将 ItemsControl 绑定到 ObservableCollection,则对此集合的更改必须 在 UI 线程上完成,因为 CollectionChanged 事件不会自动转发到 UI 线程。或者,您可以使用 ObservableCollection 的变体来引发 UI 线程上的事件 (这是一个实现

Bindings on scalar properties support updates from other threads, so you don't need to call Dispatcher.Invoke when updating a property of the model (or ViewModel). However, this is not true for binding to a collection: if you have a ItemsControl bound to an ObservableCollection<T>, changes to this collection must be done on the UI thread, as CollectionChanged events are not automatically forwarded to the UI thread. Alternatively, you could use a variant of ObservableCollection<T> that raises the event on the UI thread (here's a implementation)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文