DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs) Method

Definition

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

Parameters

e
DependencyPropertyChangedEventArgs

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

Remarks

這個方法不是用來一般偵測個別的屬性變更,也不會以每個案例為基礎來執行屬性失效。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.

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

Notes to Inheritors

一律呼叫基底實作為。Always call the base implementation. 如果無法這麼做,將會大幅停用整個 WPFWPF 的屬性系統,而造成報告的值不正確。Failure to do this will significantly disable the entire WPFWPF property system, causing incorrect values to be reported.

Applies to

See also