DependencyPropertyChangedCallback DependencyPropertyChangedCallback DependencyPropertyChangedCallback 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)
struct DependencyPropertyChangedCallback : winrt::Windows::Foundation::IUnknown
{
   DependencyPropertyChangedCallback(std::nullptr_t = nullptr) noexcept;
   template <typename L> DependencyPropertyChangedCallback(L lambda);
   template <typename F> DependencyPropertyChangedCallback(F* function);
   template <typename O, typename M> DependencyPropertyChangedCallback(O* object, M method);
   void operator()(winrt::Windows::UI::Xaml::DependencyObject const& sender, winrt::Windows::UI::Xaml::DependencyProperty const& dp) const;
};
public delegate void DependencyPropertyChangedCallback(DependencyObject sender, DependencyProperty dp)
Public Delegate Sub DependencyPropertyChangedCallback(sender As DependencyObject, dp As DependencyProperty)

Parameters

sender
DependencyObject DependencyObject

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

dp
DependencyProperty DependencyProperty

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

Attributes

Windows 10 requirements

Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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.

See also