Export (0) Print
Expand All
Expand Minimize
0 out of 1 rated this helpful - Rate this topic

RoutedPropertyChangedEventHandler Generic Delegate

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

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

'Declaration
Public Delegate Sub RoutedPropertyChangedEventHandler(Of T) ( _
	sender As Object, _
	e As RoutedPropertyChangedEventArgs(Of T) _
)
'Usage
Dim instance As New RoutedPropertyChangedEventHandler(Of T)(AddressOf HandlerMethod)
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

T

Type of the property where changes in value are reported.

Parameters

sender

Object where the event handler is being invoked.

e

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

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
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.