英語で読む

次の方法で共有


RoutedPropertyChangedEventHandler<T> 代理人

定義

プロパティ値の変更を追跡するさまざまなルーティングされたイベントを処理するメソッドを表します。

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

型パラメーター

T

値の変更が報告されたプロパティ値の型。

パラメーター

sender
Object

イベント ハンドラーがアタッチされているオブジェクト。

e
RoutedPropertyChangedEventArgs<T>

イベントのデータ。 特定のイベント定義では、RoutedPropertyChangedEventArgs<T> は型に制約され、制約の型パラメーターはデリゲート実装の型パラメーター制約に一致します。

次の例では、 イベントのハンドラー メソッド ValueChanged を定義してアタッチします。

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

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

注釈

に基づいて RoutedPropertyChangedEventHandler<T> 型制約付きデリゲートを使用するイベントの例には TreeView.SelectedItemChanged 、 と RangeBase.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

こちらもご覧ください