FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs) FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs) FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs) FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs) Method

定義

每當 FrameworkElement 上任何相依性屬性的有效值已更新時叫用。Invoked whenever the effective value of any dependency property on this FrameworkElement has been updated. 已變更的特定相依性屬性會在引數參數中報告。The specific dependency property that changed is reported in the arguments parameter. 覆寫 OnPropertyChanged(DependencyPropertyChangedEventArgs)Overrides OnPropertyChanged(DependencyPropertyChangedEventArgs).

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

參數

e
DependencyPropertyChangedEventArgs DependencyPropertyChangedEventArgs DependencyPropertyChangedEventArgs DependencyPropertyChangedEventArgs

事件資料,描述已變更的屬性,以及舊值和新值。The event data that describes the property that changed, as well as old and new values.

備註

這個方法不是用來一般偵測屬性變更或失效。This method is not intended to generally detect property changes or invalidations. 如果已知屬性的廣泛分類, 則會改為針對一般失效模式的修改。It is instead intended for modifications of the general invalidation pattern if certain information is known about wide classifications of properties.

在物件的生命週期內, 可能會多次叫用這個方法。This method is potentially invoked many times during the life of an object. 因此, 如果您覆寫特定屬性的中繼資料, 然後針對個別屬性附加CoerceValueCallbackPropertyChangedCallback函式, 則可以達到更好的效能。Therefore, you can achieve better performance if you override the metadata of specific properties and then attach CoerceValueCallback or PropertyChangedCallback functions for individual properties. 不過, 如果FrameworkElement包含大量與值相關的相依性屬性, 或如果包含的邏輯 (例如轉譯行為) 必須針對數個相關的屬性失效情況重新執行, 則您會使用這個方法。However, you would use this method if a FrameworkElement 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.

請注意, 有一個名稱OnPropertyChanged相同的方法具有不同的簽章 (參數類型為PropertyChangedEventArgs), 可出現在多個類別上。Note that there is an identically named OnPropertyChanged method with a different signature (the parameter type is PropertyChangedEventArgs) that can appear on a number of classes. OnPropertyChanged會用於資料物件通知, 而且是的INotifyPropertyChanged合約的一部分。That OnPropertyChanged is used for data object notifications, and is part of the contract for INotifyPropertyChanged.

給繼承者的注意事項

一律呼叫基底實作為您的實作為第一個作業。Always call the base implementation, as the first operation in your implementation. 若未這麼做, 將會大幅停WPFWPF用整個屬性系統, 而導致報告不正確的值。Failure to do this will significantly disable the entire WPFWPF property system, which causes incorrect values to be reported. 特定FrameworkElement的執行也會負責針對各種會影響可見使用者介面的屬性維護適當的狀態。The specific FrameworkElement implementation is also responsible for maintaining proper state for a variety of properties that affect the visible user interface. 其中包括根據適當時間的樣式變更, 使視覺化樹狀結構失效。These include invalidating the visual tree based on changes to style at appropriate times.

適用於

另請參閱