RoutedPropertyChangedEventHandler<T> 代理人

定義

表示將處理各種追蹤屬性值變更之路由事件的方法。Represents methods that will handle various routed events that track property value changes.

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

屬性值的類型,其會報告該值的變更。The type of the property value where changes in value are reported.

參數

sender
Object

附加事件處理常式的物件。The object where the event handler is attached.

e
RoutedPropertyChangedEventArgs<T>

事件資料。The event data. 特定事件定義將會限制 RoutedPropertyChangedEventArgs<T> 為某類型,其中條件約束的型別參數符合委派實作的型別參數條件約束。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.

繼承
RoutedPropertyChangedEventHandler<T>

範例

下列範例會定義和附加ValueChanged事件的處理常式方法。The following example defines and attaches a handler method for the ValueChanged event.

處理常式是以為RoutedPropertyChangedEventHandler<T>基礎, 而且是在程式碼範例的第二個區段中定義, 而且泛型的型別參數Double會限制為。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);
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

此特定範例不會使用事件的路由事件特性;事件會在其引發所在的相同元素上處理。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.

備註

根據RoutedPropertyChangedEventHandler<T>包含TreeView.SelectedItemChanged和使用類型限制委派的事件範例。RangeBase.ValueChangedExamples of events that use type-constrained delegates based on RoutedPropertyChangedEventHandler<T> include TreeView.SelectedItemChanged and RangeBase.ValueChanged.

擴充方法

GetMethodInfo(Delegate)

取得表示特定委派所代表之方法的物件。Gets an object that represents the method represented by the specified delegate.

適用於

另請參閱