RoutedPropertyChangedEventHandler(Of T) Delegate


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

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

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

Public Delegate Sub RoutedPropertyChangedEventHandler(Of T) (
	sender As Object,
	e As RoutedPropertyChangedEventArgs(Of T)


Type: System.Object

The object where the event handler is attached.

Type: System.Windows.RoutedPropertyChangedEventArgs(Of T)

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

Type Parameters


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

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

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

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

Dim childrenCountSlider As Slider = CType(LogicalTreeHelper.FindLogicalNode(myWindow, "ChildrenCountSlider"), Slider)
AddHandler childrenCountSlider.ValueChanged, AddressOf OnChildrenCountChanged
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()
		c.Style = CType(c.FindResource("ImageWithBorder"), Style)
	Do While g.Children.Count > childrenCount
		g.Children.Remove(g.Children(g.Children.Count - 1))

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

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.

.NET Framework
Available since 3.0
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top