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)

protected virtual void OnPropertyChanged (
	DependencyPropertyChangedEventArgs e
)
protected void OnPropertyChanged (
	DependencyPropertyChangedEventArgs e
)
protected function OnPropertyChanged (
	e : DependencyPropertyChangedEventArgs
)
You cannot use methods in XAML.

Parameters

e

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. It 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 in which the changes are within other Freezable references. The Freezable override implementation of OnPropertyChanged uses the method event arguments to determine whether the properties are subproperties, and provides appropriate base class logic for either case.

This method 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.

NoteImportant:

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

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

  • Do not enter any message pump from within OnPropertyChanged. Messages may trigger further property changes.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2014 Microsoft