RoutedPropertyChangedEventHandler<T> Delegado

Definición

Representa métodos que controlarán diversos eventos enrutados que realizan el seguimiento de los cambios de valor de propiedad.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))

Parámetros de tipo

T

Tipo del valor de propiedad donde se notifican los cambios de valor.The type of the property value where changes in value are reported.

Parámetros

sender
Object

Objeto en que está asociado el controlador de eventos.The object where the event handler is attached.

e
RoutedPropertyChangedEventArgs<T>

Datos del evento.The event data. Las definiciones de eventos específicos restringirán RoutedPropertyChangedEventArgs<T> a un tipo, coincidiendo el parámetro de tipo de la restricción con la restricción de parámetro de tipo de una implementación de delegado.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.

Herencia
RoutedPropertyChangedEventHandler<T>

Ejemplos

En el ejemplo siguiente se define y se asocia un método de controlador para el ValueChanged evento.The following example defines and attaches a handler method for the ValueChanged event.

El controlador se basa en RoutedPropertyChangedEventHandler<T> y se define en el segundo segmento del ejemplo de código, con el parámetro de tipo de la restricción genérica en 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

En este ejemplo concreto no se usa la característica de evento enrutado del evento; el evento se controla en el mismo elemento en el que se genera.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. Pero no siempre es así.This is not always the case. Para un evento enrutado, es posible que el origen del evento sea un objeto diferente que el objeto al que está asociado el controlador.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.

Comentarios

Ejemplos de eventos que usan delegados restringidos por tipo basados en RoutedPropertyChangedEventHandler<T> incluyen TreeView.SelectedItemChanged y RangeBase.ValueChanged .Examples of events that use type-constrained delegates based on RoutedPropertyChangedEventHandler<T> include TreeView.SelectedItemChanged and RangeBase.ValueChanged.

Métodos de extensión

GetMethodInfo(Delegate)

Obtiene un objeto que representa el método representado por el delegado especificado.Gets an object that represents the method represented by the specified delegate.

Se aplica a

Consulte también