DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs) 方法

定義

每當這個 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.

protected:
 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)

參數

e
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. @No__t-1 的 Freezable 覆寫執行會使用內部資訊來判斷屬性是否為子類別,並為任一案例提供適當的基類邏輯。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.

在物件的生命週期內,可能會多次叫用 OnPropertyChangedOnPropertyChanged 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.

適用於

另請參閱