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.

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

適用於

另請參閱