RoutedPropertyChangedEventHandler<T> Delegato
Definizione
Rappresenta i metodi che gestiranno i vari eventi indirizzati che tengono traccia delle modifiche dei valori delle proprietà.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))
Parametri di tipo
- T
Tipo del valore della proprietà in cui vengono segnalate le modifiche al valore.The type of the property value where changes in value are reported.
Parametri
- sender
- Object
Oggetto a cui è associato il gestore eventi.The object where the event handler is attached.
Dati dell'evento.The event data. Tramite definizioni dell'evento specifiche, l'oggetto RoutedPropertyChangedEventArgs<T> è vincolato a un tipo, in cui il parametro di tipo del vincolo corrisponde al vincolo del parametro di tipo dell'implementazione di un delegato.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.
- Ereditarietà
Esempio
Nell'esempio seguente viene definito e collegato un metodo del gestore per l' ValueChanged evento.The following example defines and attaches a handler method for the ValueChanged event.
Il gestore si basa su RoutedPropertyChangedEventHandler<T> e viene definito nel secondo segmento dell'esempio di codice, con il parametro di tipo dell'oggetto generico vincolato a 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
Questo particolare esempio non usa la caratteristica dell'evento indirizzato dell'evento. l'evento viene gestito sullo stesso elemento su cui è stato generato.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. Questo non è sempre il caso.This is not always the case. Per un evento indirizzato, è possibile che l'origine dell'evento sia un oggetto diverso rispetto all'oggetto a cui è associato il gestore.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.
Commenti
Esempi di eventi che usano delegati con vincoli di tipo basati su RoutedPropertyChangedEventHandler<T> includono TreeView.SelectedItemChanged e RangeBase.ValueChanged .Examples of events that use type-constrained delegates based on RoutedPropertyChangedEventHandler<T> include TreeView.SelectedItemChanged and RangeBase.ValueChanged.
Metodi di estensione
GetMethodInfo(Delegate) |
Ottiene un oggetto che rappresenta il metodo rappresentato dal delegato specificato.Gets an object that represents the method represented by the specified delegate. |