簡體   English   中英

在 WPF 中,一旦建立數據綁定,依賴項 object 是否訂閱了 NotifyPropertyChanged 事件?

[英]In WPF, is the dependency object subcribing the NotifyPropertyChanged Event once the databinding is established?

我知道要讓 object 的屬性能夠成為數據綁定的目標,它必須實現 INotifyPropertyChanged。

以前,我認為數據綁定一旦建立,依賴 object 就會訂閱目標 object 的 NotifyPropertyChanged 事件。 This also make sense for the fact that databinding is not allowed to be made targeting an object in another thread as WPF want to make its UI thread safe from other thread and subcribing Notifyproperty changed event of an object in another would make that object call subcriber's method ,它修改 UI 線程。

然而,當我閱讀 Dispatcher 時,我開始懷疑。 在 DispatcherPriority Enum 中,數字 8 是 DataBind,具有此調度程序優先級的操作以與數據綁定相同的優先級處理。 這意味着數據綁定建立者(依賴對象)實際上通過定期檢查綁定目標來更新其值。

這是真的?

我很困惑。 如果第二個假設為真,那么為什么不允許數據綁定到另一個線程? 而且似乎即使 INotifyPropertyChanged 也不是真正必要的,因為在獲取綁定屬性時定期調用,而不是僅僅讀取指示它是否已更改的值,這只是額外的性能成本問題。

我知道要讓 object 的屬性能夠成為數據綁定的目標,它必須實現 INotifyPropertyChanged。

以前,我認為數據綁定一旦建立,依賴 object 就會訂閱目標 object 的 NotifyPropertyChanged 事件。 This also make sense for the fact that databinding is not allowed to be made targeting an object in another thread as WPF want to make its UI thread safe from other thread and subcribing Notifyproperty changed event of an object in another would make that object call subcriber's method ,它修改 UI 線程。

然而,當我閱讀 Dispatcher 時,我開始懷疑。 在 DispatcherPriority Enum 中,數字 8 是 DataBind,具有此調度程序優先級的操作以與數據綁定相同的優先級處理。 這意味着數據綁定建立者(依賴對象)實際上通過定期檢查綁定目標來更新其值。

這是真的?

我很困惑。 如果第二個假設為真,那么為什么不允許數據綁定到另一個線程? 而且似乎即使 INotifyPropertyChanged 也不是真正必要的,因為在獲取綁定屬性時定期調用,而不是僅僅讀取指示它是否已更改的值,這只是額外的性能成本問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM