RoutedPropertyChangedEventHandler<T> Delegate
Represents methods that will handle various routed events that track property value changes.
Assembly: PresentationFramework (in PresentationFramework.dll)
public delegate void RoutedPropertyChangedEventHandler<T>( object sender, RoutedPropertyChangedEventArgs<T> e )
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.
Type Parameters
- T
The type of the property value where changes in value are reported.
Examples of events that use type-constrained delegates based on RoutedPropertyChangedEventHandler<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<T>, and is defined in the second segment of the code example, with the type parameter of the generic constrained to 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(); }
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.
Available since 3.0
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0