Edit

Share via


RoutedPropertyChangedEventHandler<T> Delegate

Definition

Represents methods that will handle various routed events that track property value changes.

C#
public delegate void RoutedPropertyChangedEventHandler<T>(object sender, RoutedPropertyChangedEventArgs<T> e);

Type Parameters

T

The type of the property value where changes in value are reported.

Parameters

sender
Object

The object where the event handler is attached.

e
RoutedPropertyChangedEventArgs<T>

The event data. Specific event definitions will constrain RoutedPropertyChangedEventArgs<T> to a type, with the type parameter of the constraint matching the type parameter constraint of a delegate implementation.

Examples

The following example defines and attaches a handler method for the ValueChanged event.

The handler is based on RoutedPropertyChangedEventHandler<T>, and is defined in the second segment of the code example, with the type parameter of the generic constrained to Double.

C#
Slider childrenCountSlider = (Slider)LogicalTreeHelper.FindLogicalNode(myWindow, "ChildrenCountSlider");
childrenCountSlider.ValueChanged += new RoutedPropertyChangedEventHandler<double>(OnChildrenCountChanged);
C#
private void OnChildrenCountChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
    int childrenCount = (int)Math.Floor(e.NewValue + 0.5);

    //  Update the children count...
    AutoIndexingGrid g = (AutoIndexingGrid)LogicalTreeHelper.FindLogicalNode(myWindow, "TargetGrid");
    while (g.Children.Count < childrenCount)
    {
        Control c = new Control();
        g.Children.Add(c);
        c.Style = (Style)c.FindResource("ImageWithBorder");
    }
    while (g.Children.Count > childrenCount)
    {
        g.Children.Remove(g.Children[g.Children.Count - 1]);
    }


    //  Update TextBlock element displaying the count...
    TextBlock t = (TextBlock)LogicalTreeHelper.FindLogicalNode(myWindow, "ChildrenCountDisplay");
    t.Text = childrenCount.ToString();
}

This particular example does not use the routed-event characteristic of the event; the event is handled on the same element that it is raised on. This is not always the case. For a routed event, it is possible that the source of the event is a different object than the object where the handler is attached.

Remarks

Examples of events that use type-constrained delegates based on RoutedPropertyChangedEventHandler<T> include TreeView.SelectedItemChanged and RangeBase.ValueChanged.

Extension Methods

GetMethodInfo(Delegate)

Gets an object that represents the method represented by the specified delegate.

Applies to

Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

See also