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>基づいており、コード例の 2 番目のセグメントで定義され、ジェネリックの型パラメーターは に 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

この特定の例では、 イベントの routed-event 特性は使用しません。イベントは、発生したのと同じ要素で処理されます。 常にそうであるとは限りません。 ルーティング イベントの場合、イベントのソースがハンドラーがアタッチされているオブジェクトとは異なるオブジェクトである可能性があります。

注釈

に基づいて RoutedPropertyChangedEventHandler<T> 型制約付きデリゲートを使用するイベントの例には TreeView.SelectedItemChanged 、 と RangeBase.ValueChangedがあります。

拡張メソッド

GetMethodInfo(Delegate)

指定したデリゲートによって表されるメソッドを表すオブジェクトを取得します。

適用対象

こちらもご覧ください