ExecutedRoutedEventHandler 代理人
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
代表處理ExecutedPreviewExecuted路由事件及相關附加事件的方法。
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 類別中附加事件。 但大多數實務操作者會處理 Executed 特定 CommandBinding事件,而非在層 CommandManager 級工作。
在 ExecutedRoutedEventArgs中,當你為路由事件撰寫事件處理程序時,通常會關注以下屬性:
Command 報告執行指令。 這個特性對於使用指令綁定或撰寫能處理多個指令的處理器非常有用。
Parameter 回報執行指令所傳遞的任何特定指令參數。 並非所有指令都會使用或期待特定指令的參數。
Handled 報告執行指令所產生的路由事件是否已被路徑上的另一個元件處理。 對於路由事件處理程序,建議將處理程序 Handled 設定為
true。 這會防止事件的典型處理者在路徑上再次處理該事件。 欲了解更多處理路由事件的資訊,請參閱 「標記路由事件為已處理」及「類別處理」。
此代理同時代表 和 CommandManager.PreviewExecutedEvent的處理程序CommandManager.Executed,這些處理者是實作大部分指令基礎設施的CommandManager類別中附加的事件。 但大多數實務操作者會處理 Executed 特定 CommandBinding事件,而非在層 CommandManager 級工作。
如需命令的詳細資訊,請參閱命令概觀。
擴充方法
| 名稱 | Description |
|---|---|
| GetMethodInfo(Delegate) |
取得一個代表指定代理所代表方法的物件。 |