Export (0) Print
Expand All

DependencyObject.OnPropertyChanged Method

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.

Namespace:  System.Windows
Assembly:  WindowsBase (in WindowsBase.dll)

abstract OnPropertyChanged : 
        e:DependencyPropertyChangedEventArgs -> unit  
override OnPropertyChanged : 
        e:DependencyPropertyChangedEventArgs -> unit

Parameters

e
Type: System.Windows.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 is instead intended for modifications of the general invalidation pattern, if certain information is known about wide classifications of properties. 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. 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 is potentially invoked many times during the life of an object. 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. 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. Failure to do this will significantly disable the entire WPF property system, causing incorrect values to be reported.

Important noteImportant

The OnPropertyChanged method has high potential for introducing reentrancy issues through your implementation. Avoid the following possible reentrancy cases when implementing:

Do not introduce modal UI or otherwise hold up the UI thread.

Do not enter any message pump from within OnPropertyChanged. Message responses (in particular, native handling that you might not be aware of) might trigger further property changes.

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft