FrameworkContentElement.OnPropertyChanged(DependencyPropertyChangedEventArgs) 方法


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

 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)



描述已變更屬性的事件資料 (包含舊值和新值)。The event data that describes the property that changed, including the 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. 不過,如果 FrameworkContentElement 包含大量的值相關相依性屬性,或如果它包含的邏輯(例如轉譯行為)必須針對數個相關的屬性失效案例重新執行,則您會使用這個方法。However, you would use this method if a FrameworkContentElement 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.