Export (0) Print
Expand All
Expand Minimize

DependencyPropertyChangedEventHandler Delegate

Represents the method that will handle the event raised when a DependencyProperty is changed on a DependencyObject.

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

'Declaration
Public Delegate Sub DependencyPropertyChangedEventHandler ( _
	sender As Object, _
	e As DependencyPropertyChangedEventArgs _
)
'Usage
Dim instance As New DependencyPropertyChangedEventHandler(AddressOf HandlerMethod)
/** @delegate */
public delegate void DependencyPropertyChangedEventHandler (
	Object sender, 
	DependencyPropertyChangedEventArgs e
)
In XAML, you can use delegates but you cannot define your own.

Parameters

sender

The object that handled the event.

e

The DependencyPropertyChangedEventArgs arguments of the event.

This delegate has three usages: for particular events that report property changes, for PropertyChangedCallback implementations, and for the OnPropertyChanged virtual method.

Property Changed Events: Events that use this handler are exposed as a common language runtime (CLR) event, not as a routed event. Typically these events follow the naming pattern Is(PropertyName)Changed, where PropertyName is the DependencyProperty.Name of the property that changed. The arguments of the event are used to query the old and new value of the property, as reported by the particular event. Typically there is a 1:1 correspondence between properties that change and a particular event that reports the change. It is also possible, though uncommon, to have the same event report changes to more than one property. In this case, the DependencyPropertyChangedEventArgs should be checked to determine the property that changed.

PropertyChangedCallback: This callback is used when registering a dependency property, and you want your property to have additional logic executed every time the property system determines that there is an effective value change. This callback is commonly used for just-in-time validation, and also for coercion mechanisms where property values are dependent on other values. For more information, see Dependency Property Callbacks and Validation.

OnPropertyChanged: OnPropertyChanged virtual. This callback is useful for elements that need to be informed of changes to any of their properties; for instance the FrameworkElement implementation of OnPropertyChanged is used to determine whether the property in question is one that requires a new composition for layout. Overriding this virtual is usually only necessary if your element has a great number of interdependencies between properties, or behaviors that rely on detecting changes to broad classifications of properties as based on their metadata or other known characteristics.

The following example uses the delegate to implement a PropertyChangedCallback, also showing the Register call that sets the delegate, and the property wrapper. For the complete sample, see Custom Classes with Dependency Properties Sample.

public static readonly DependencyProperty ButtonColorProperty = DependencyProperty.Register(
    "ButtonColor",
    typeof(ButtonColors), 
    typeof(Shirt), 
    new FrameworkPropertyMetadata(
    ButtonColors.Black,
    new PropertyChangedCallback(OnButtonColorChangedCallback),
    new CoerceValueCallback(CoerceButtonColor))
);
public ButtonColors ButtonColor
{
    get { return (ButtonColors)GetValue(ButtonColorProperty); }
    set { SetValue(ButtonColorProperty, value); }
}
private static void OnButtonColorChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
    RoutedEventArgs newargs = new RoutedEventArgs(ButtonColorChangedEvent);
    (d as FrameworkElement).RaiseEvent(newargs);
}

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