RoutedPropertyChangedEventHandler<T> 委托

定义

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

C#
public delegate void RoutedPropertyChangedEventHandler<T>(object sender, RoutedPropertyChangedEventArgs<T> e);

类型参数

T

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

参数

sender
Object

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

e
RoutedPropertyChangedEventArgs<T>

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

示例

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

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

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

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

注解

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

扩展方法

GetMethodInfo(Delegate)

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

适用于

产品 版本
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

另请参阅