RoutedPropertyChangedEventHandler<T> 委托

定义

表示将处理跟踪属性值更改的各个路由事件的方法。

generic <typename T>
public delegate void RoutedPropertyChangedEventHandler(System::Object ^ sender, RoutedPropertyChangedEventArgs<T> ^ e);
public delegate void RoutedPropertyChangedEventHandler<T>(object sender, RoutedPropertyChangedEventArgs<T> e);
type RoutedPropertyChangedEventHandler<'T> = delegate of obj * RoutedPropertyChangedEventArgs<'T> -> unit
Public Delegate Sub RoutedPropertyChangedEventHandler(Of T)(sender As Object, e As RoutedPropertyChangedEventArgs(Of T))

类型参数

T

在其中报告了值更改的属性值的类型。

参数

sender
Object

事件处理程序所附加到的对象。

e
RoutedPropertyChangedEventArgs<T>

事件数据。 特定事件定义会使用与委托实现的类型参数约束匹配的约束的类型参数,将 RoutedPropertyChangedEventArgs<T> 约束为某种类型。

示例

下面的示例定义并附加事件的处理程序方法 ValueChanged

处理程序基于 RoutedPropertyChangedEventHandler<T>,并在代码示例的第二个段中定义,泛型 的类型参数约束为 Double

Slider childrenCountSlider = (Slider)LogicalTreeHelper.FindLogicalNode(myWindow, "ChildrenCountSlider");
childrenCountSlider.ValueChanged += new RoutedPropertyChangedEventHandler<double>(OnChildrenCountChanged);
Dim childrenCountSlider As Slider = CType(LogicalTreeHelper.FindLogicalNode(myWindow, "ChildrenCountSlider"), Slider)
AddHandler childrenCountSlider.ValueChanged, AddressOf 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();
}
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

此特定示例不使用 事件的路由事件特征;在引发事件的同一元素上处理事件。 但不总是这样。 对于路由事件,事件的源可能与附加处理程序的对象不同。

注解

使用基于 RoutedPropertyChangedEventHandler<T> include TreeView.SelectedItemChangedRangeBase.ValueChanged的类型约束委托的事件示例。

扩展方法

GetMethodInfo(Delegate)

获取指示指定委托表示的方法的对象。

适用于

另请参阅