RoutedPropertyChangedEventHandler<T> 代理人
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
プロパティ値の変更を追跡するさまざまなルーティング イベントを処理するメソッドを表します。
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))
型パラメーター
- T
値の変更が報告されるプロパティ値の型。
パラメーター
- sender
- Object
イベント ハンドラーがアタッチされているオブジェクト。
イベントのデータ。 特定のイベント定義では、デリゲート実装の型パラメーター制約と一致する制約の型パラメーターを使用して、 RoutedPropertyChangedEventArgs<T> を型に制限します。
例
次の例では、 ValueChanged イベントのハンドラー メソッドを定義してアタッチします。
ハンドラーは RoutedPropertyChangedEventHandler<T>に基づいており、コード例の 2 番目のセグメントで定義され、ジェネリックの型パラメーターが 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
この特定の例では、イベントのルーティング イベント特性は使用されません。イベントは、イベントが発生したのと同じ要素で処理されます。 これは必ずしも当てはまるとは限りません。 ルーティング イベントの場合、イベントのソースがハンドラーがアタッチされているオブジェクトとは異なるオブジェクトである可能性があります。
注釈
RoutedPropertyChangedEventHandler<T>に基づいて型制約付きデリゲートを使用するイベントの例としては、TreeView.SelectedItemChangedとRangeBase.ValueChangedがあります。
拡張メソッド
| 名前 | 説明 |
|---|---|
| GetMethodInfo(Delegate) |
指定したデリゲートによって表されるメソッドを表すオブジェクトを取得します。 |