ExecutedRoutedEventHandler 代理人
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
ExecutedおよびPreviewExecutedルーティング イベント、および関連する添付イベントを処理するメソッドを表します。
public delegate void ExecutedRoutedEventHandler(System::Object ^ sender, ExecutedRoutedEventArgs ^ e);
public delegate void ExecutedRoutedEventHandler(object sender, ExecutedRoutedEventArgs e);
type ExecutedRoutedEventHandler = delegate of obj * ExecutedRoutedEventArgs -> unit
Public Delegate Sub ExecutedRoutedEventHandler(sender As Object, e As ExecutedRoutedEventArgs)
パラメーター
- sender
- Object
イベント ハンドラーがアタッチされているオブジェクト。
イベントのデータ。
例
次の使用例は、コマンドの実行時にターゲットにビジュアル プロパティを設定する ExecutedRoutedEventHandler を作成します。 この例には、同じコマンドの CanExecuteRoutedEventHandler も含まれています。
// ExecutedRoutedEventHandler for the custom color command.
private void ColorCmdExecuted(object sender, ExecutedRoutedEventArgs e)
{
Panel target = e.Source as Panel;
if (target != null)
{
if (target.Background == Brushes.AliceBlue)
{
target.Background = Brushes.LemonChiffon;
}
else
{
target.Background = Brushes.AliceBlue;
}
}
}
// CanExecuteRoutedEventHandler for the custom color command.
private void ColorCmdCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
if (e.Source is Panel)
{
e.CanExecute = true;
}
else
{
e.CanExecute = false;
}
}
' ExecutedRoutedEventHandler for the custom color command.
Private Sub ColorCmdExecuted(ByVal sender As Object, ByVal e As ExecutedRoutedEventArgs)
Dim target As Panel = TryCast(e.Source, Panel)
If target IsNot Nothing Then
If target.Background Is Brushes.AliceBlue Then
target.Background = Brushes.LemonChiffon
Else
target.Background = Brushes.AliceBlue
End If
End If
End Sub
' CanExecuteRoutedEventHandler for the custom color command.
Private Sub ColorCmdCanExecute(ByVal sender As Object, ByVal e As CanExecuteRoutedEventArgs)
If TypeOf e.Source Is Panel Then
e.CanExecute = True
Else
e.CanExecute = False
End If
End Sub
注釈
このデリゲートには、 RoutedCommandの実装ロジックが含まれています。 実装ロジックをコマンドから分離すると、さまざまなソースと種類からコマンドを呼び出し、コマンド ロジックを一元化できます。
このデリゲートは、 CommandManager.Executed と CommandManager.PreviewExecutedにも使用されます。これは、コマンド実行インフラストラクチャの多くを実装する CommandManager クラスのイベントにアタッチされます。 ただし、ほとんどの実用的なハンドラーは、CommandManager レベルで動作するのではなく、特定のCommandBindingからのExecuted イベントを処理します。
ExecutedRoutedEventArgs内では、一般に、実行されたコマンドから発生するルーティング イベントのイベント ハンドラーを記述するときに、次のプロパティが重要になります。
Source は、コマンドが実行されたターゲットを報告します。 コマンドが実行されたら、ルーティング イベントの用語で Source をより一般的に考えることもできます。これは、ルーティング イベントを発生させたオブジェクトと考えることができます。
Command は、実行されたコマンドを報告します。 このプロパティは、コマンド バインドを使用する場合や、複数のコマンドを処理する可能性があるハンドラーを記述する場合に便利です。
Parameter は、実行中のコマンドによって渡されたコマンド固有のパラメーターを報告します。 すべてのコマンドがコマンド固有のパラメーターを使用または想定しているわけではありません。
Handled は、実行されたコマンドから発生したルーティング イベントが、ルートに沿って別の要素によって既に処理されたかどうかを報告します。 ルーティング イベント ハンドラーの場合は、イベントを処理するときに意味のある作業を行うハンドラーを用意し、 Handled を
trueに設定することをお勧めします。 これにより、イベントの一般的なハンドラーが、ルートに沿ってイベントを再び処理できなくなります。 ルーティング イベントの処理の詳細については、「ルーティング イベントを 処理済みとしてマークする」および「クラス処理」を参照してください。
このデリゲートは、 CommandManager.Executed と CommandManager.PreviewExecutedEventのハンドラーも表します。これは、コマンド処理インフラストラクチャの多くを実装する CommandManager クラスのイベントにアタッチされます。 ただし、ほとんどの実用的なハンドラーは、CommandManager レベルで動作するのではなく、特定のCommandBindingからのExecuted イベントを処理します。
コマンド実行の詳細については、「 コマンド実行の概要」を参照してください。
拡張メソッド
| 名前 | 説明 |
|---|---|
| GetMethodInfo(Delegate) |
指定したデリゲートによって表されるメソッドを表すオブジェクトを取得します。 |