RoutedPropertyChangedEventHandler Generic Delegate

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

Namespace: System.Windows
Assembly: PresentationFramework (in presentationframework.dll)

generic<typename T>
public delegate void RoutedPropertyChangedEventHandler (
	Object^ sender, 
	RoutedPropertyChangedEventArgs<T>^ e
J# supports the use of generic types and methods, but not the declaration of new ones.
JScript does not support generic types and methods.
In XAML, you can use delegates but you cannot define your own.

Type Parameters


Type of the property where changes in value are reported.



Object where the event handler is being invoked.


Generic arguments of the event. Specific event implementations typically have changed this generic to a closed type, rather than the open type, with the type parameter matching the type parameter of the delegate.

Examples of events that use type-constrained delegates based on RoutedPropertyChangedEventHandler include TextBoxBase.SelectionChanged, Selector.SelectionChanged and RangeBase.ValueChanged.

Most property-changed routed events do not route (although sometimes they are direct routed events), because in most object models only the object that owns the changed property will have an appropriate response, and therefore routing the event is unnecessary. The RoutedPropertyChangedEventHandler delegate is used for events where routing the property change notification is desirable.

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

The handler is based on RoutedPropertyChangedEventHandler, and is defined in the second segment of the code example, with the type parameter of the generic set as Double.

Slider childrenCountSlider = (Slider)LogicalTreeHelper.FindLogicalNode(myWindow, "ChildrenCountSlider");
childrenCountSlider.ValueChanged += new RoutedPropertyChangedEventHandler<double>(OnChildrenCountChanged);

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();
        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();

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