閱讀英文

共用方式為


RoutedPropertyChangedEventHandler<T> 代理人

定義

表示將處理各種追蹤屬性值變更之路由事件的方法。

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

類型參數

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);
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> include TreeView.SelectedItemChangedRangeBase.ValueChanged ,使用型別限制委派的事件範例。

擴充方法

GetMethodInfo(Delegate)

取得表示特定委派所代表之方法的物件。

適用於

另請參閱