RoutedPropertyChangedEventHandler(T) Delegate (System.Windows)

Switch View :
ScriptFree
.NET Framework Class Library
RoutedPropertyChangedEventHandler<T> Delegate

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

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

Visual Basic
Public Delegate Sub RoutedPropertyChangedEventHandler(Of T) ( _
	sender As Object, _
	e As RoutedPropertyChangedEventArgs(Of T) _
)
C#
public delegate void RoutedPropertyChangedEventHandler<T>(
	Object sender,
	RoutedPropertyChangedEventArgs<T> e
)

Visual C++
generic<typename T>
public delegate void RoutedPropertyChangedEventHandler(
	Object^ sender, 
	RoutedPropertyChangedEventArgs<T>^ e
)
F#
type RoutedPropertyChangedEventHandler = 
    delegate of 
        sender:Object * 
        e:RoutedPropertyChangedEventArgs<'T> -> unit

Type Parameters

T

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

Parameters

sender
Type: System.Object
The object where the event handler is attached.
e
Type: System.Windows.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.
Remarks

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

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.

Visual Basic

			Dim childrenCountSlider As Slider = CType(LogicalTreeHelper.FindLogicalNode(myWindow, "ChildrenCountSlider"), Slider)
			AddHandler childrenCountSlider.ValueChanged, AddressOf OnChildrenCountChanged


C#

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


Visual Basic

		Private Sub OnChildrenCountChanged(ByVal sender As Object, ByVal e As RoutedPropertyChangedEventArgs(Of Double))
			Dim childrenCount As Integer = CInt(Fix(Math.Floor(e.NewValue + 0.5)))

			'  Update the children count...
			Dim g As AutoIndexingGrid = CType(LogicalTreeHelper.FindLogicalNode(myWindow, "TargetGrid"), AutoIndexingGrid)
			Do While g.Children.Count < childrenCount
				Dim c As New Control()
				g.Children.Add(c)
				c.Style = CType(c.FindResource("ImageWithBorder"), Style)
			Loop
			Do While g.Children.Count > childrenCount
				g.Children.Remove(g.Children(g.Children.Count - 1))
			Loop


			'  Update TextBlock element displaying the count...
			Dim t As TextBlock = CType(LogicalTreeHelper.FindLogicalNode(myWindow, "ChildrenCountDisplay"), TextBlock)
			t.Text = childrenCount.ToString()
		End Sub


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.

Version Information

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
See Also

Reference

Other Resources