DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs) DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs) DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs) DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs) Method


每當這個 DependencyObject 上任何相依性屬性的有效值已更新時叫用。Invoked whenever the effective value of any dependency property on this DependencyObject has been updated. 已變更的特定相依性屬性會在事件資料中報告。The specific dependency property that changed is reported in the event data.

 virtual void OnPropertyChanged(System::Windows::DependencyPropertyChangedEventArgs e);
protected virtual void OnPropertyChanged (System.Windows.DependencyPropertyChangedEventArgs e);
abstract member OnPropertyChanged : System.Windows.DependencyPropertyChangedEventArgs -> unit
override this.OnPropertyChanged : System.Windows.DependencyPropertyChangedEventArgs -> unit
Protected Overridable Sub OnPropertyChanged (e As DependencyPropertyChangedEventArgs)


DependencyPropertyChangedEventArgs DependencyPropertyChangedEventArgs DependencyPropertyChangedEventArgs DependencyPropertyChangedEventArgs

事件資料,其中包含相關的相依性屬性識別項、型別的屬性中繼資料,以及舊值和新值。Event data that will contain the dependency property identifier of interest, the property metadata for the type, and old and new values.


這個方法不是偵測一般的個別屬性的變更,或執行每個案例為基礎的屬性的失效。This method is not intended to generally detect individual property changes or perform invalidations of properties on a per-case basis. OnPropertyChanged 而被適用於修改一般失效模式中,如果已知廣泛分類屬性的特定資訊。OnPropertyChanged is instead intended for modifications of the general invalidation pattern, if certain information is known about wide classifications of properties. 例如,變更Freezable可能會變更中的實值類型Freezable,或可能是子屬性,而所做的變更都在其他Freezable參考。For example, changes in a Freezable might be changes in the value types of the Freezable, or might be subproperties, where the changes are within other Freezable references. Freezable覆寫的實作OnPropertyChanged,判斷是否屬性是子屬性,並提供適當的基底類別的邏輯以任一種情況下會使用內部的資訊。The Freezable override implementation of OnPropertyChanged uses internal information to determine whether the properties are subproperties, and provides appropriate base class logic for either case.

OnPropertyChanged 是可能叫用次數的物件存留期間。OnPropertyChanged is potentially invoked many times during the life of an object. 因此,達到更佳的效能,整體的屬性系統,如果您覆寫特定屬性的中繼資料,然後將附加CoerceValueCallbackPropertyChangedCallback個別屬性的函式。Therefore, you can achieve better performance for the overall property system if you override the metadata of specific properties and then attach CoerceValueCallback or PropertyChangedCallback functions for individual properties. 不過,您會使用這個方法如果DependencyObject包含大量的值相互關聯的相依性屬性,或者如果它包含邏輯,例如轉譯行為,必須重新執行的許多相關的屬性失效的情況。However, you would use this method if a DependencyObject includes a significant number of value-interrelated dependency properties, or if it includes logic such as rendering behavior that must be rerun for several related cases of property invalidations.


請務必呼叫基底實作。Always call the base implementation. 如果沒有這樣做會大幅停用整個WPFWPF屬性系統中,導致報告不正確的值。Failure to do this will significantly disable the entire WPFWPF property system, causing incorrect values to be reported.