FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs) 方法

定义

每当更新此 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

描述已更改的属性的事件数据(包括旧值和新值)。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.

适用于

另请参阅