RoutedPropertyChangedEventHandler<T> Delegat

Definicja

Reprezentuje metody, które będą obsługiwać różne zdarzenia kierowane, które śledzą zmiany wartości właściwości.

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))

Parametry typu

T

Typ wartości właściwości, w której są zgłaszane zmiany wartości.

Parametry

sender
Object

Obiekt, w którym jest dołączony program obsługi zdarzeń.

e
RoutedPropertyChangedEventArgs<T>

Dane dotyczące zdarzenia. Określone definicje zdarzeń będą ograniczać RoutedPropertyChangedEventArgs<T> do typu, z parametrem typu ograniczenia zgodnego z ograniczeniem parametru typu implementacji delegata.

Przykłady

Poniższy przykład definiuje i dołącza metodę obsługi dla ValueChanged zdarzenia.

Procedura obsługi jest oparta na parametrze RoutedPropertyChangedEventHandler<T>i jest definiowana w drugim segmencie przykładu kodu z parametrem typu ogólnego ograniczonego do 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

W tym konkretnym przykładzie nie jest używana cecha zdarzenia kierowanego; zdarzenie jest obsługiwane w tym samym elemecie, na który jest wywoływany. Nie zawsze tak jest. W przypadku zdarzenia kierowanego możliwe jest, że źródłem zdarzenia jest inny obiekt niż obiekt, w którym jest dołączony program obsługi.

Uwagi

Przykłady zdarzeń korzystających z delegatów ograniczonych typami na RoutedPropertyChangedEventHandler<T> podstawie elementów include TreeView.SelectedItemChanged i RangeBase.ValueChanged.

Metody rozszerzania

GetMethodInfo(Delegate)

Pobiera obiekt reprezentujący metodę reprezentowaną przez określonego delegata.

Dotyczy

Zobacz też