Jaa


DependencyPropertyChangedCallback Delegate

Definition

Represents the callback that is invoked when a property value changes, for property change notifications that are registered with the RegisterPropertyChangedCallback technique.

public delegate void DependencyPropertyChangedCallback(DependencyObject ^ sender, DependencyProperty ^ dp);
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.Guid(1166556438, 10175, 19393, 172, 38, 148, 193, 96, 31, 58, 73)]
class DependencyPropertyChangedCallback : MulticastDelegate
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.Guid(1166556438, 10175, 19393, 172, 38, 148, 193, 96, 31, 58, 73)]
public delegate void DependencyPropertyChangedCallback(DependencyObject sender, DependencyProperty dp);
Public Delegate Sub DependencyPropertyChangedCallback(sender As DependencyObject, dp As DependencyProperty)

Parameters

sender
DependencyObject

The object instance that holds the property to register for property-changed notification.

dp
DependencyProperty

The dependency property identifier of the property to register for property-changed notification.

Attributes

Windows requirements

Device family
Windows 10 (introduced in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)

Examples

This example shows how to use a DependencyPropertyChangedCallback delegate to listen for changes to the Tag property on a TextBlock.

<TextBlock x:Name="textBlock1" Text="Hello, world"/>
long tagToken;
protected override void OnNavigatedTo(NavigationEventArgs e)
{
    long tagToken = textBlock1.RegisterPropertyChangedCallback(TextBlock.TagProperty, tbTagChangedCallback);
    base.OnNavigatedTo(e);

    textBlock1.Tag = "name";
}

protected override void OnNavigatedFrom(NavigationEventArgs e)
{
    textBlock1.UnregisterPropertyChangedCallback(TextBlock.TagProperty, tagToken);
    base.OnNavigatedFrom(e);
}

private void tbTagChangedCallback(DependencyObject sender, DependencyProperty dp)
{
    if (dp == TextBlock.TagProperty)
    {
       // These lines produce the same result.
       System.Diagnostics.Debug.WriteLine("The tag has been set to " + ((TextBlock)sender).Tag);
       System.Diagnostics.Debug.WriteLine("The tag has been set to " + sender.GetValue(dp));
    }
}

Remarks

The parameter values of the delegate are based on the parameter given to the RegisterPropertyChangedCallback invocation that registered a particular property for property-changed notification, and the instance that invoked it.

Because the callback has the dp parameter that identifies which property value changed, you can use the same callback to handle multiple property-changed cases, and your logic can write cases for each different property.

For performance reasons, you don't get an OldValue / NewValue property pair from a PropertyChangedCallback method like you do from DependencyPropertyChangedEventArgs. The property value is changed before the callback, so once the method has been invoked, you can call DependencyObject.GetValue to retrieve the new value.

Applies to

See also