CanExecuteRoutedEventHandler 代理人

定義

表示處理 CanExecute 事件的方法。

C#
public delegate void CanExecuteRoutedEventHandler(object sender, CanExecuteRoutedEventArgs e);

參數

sender
Object

正在叫用處理常式的命令目標。

e
CanExecuteRoutedEventArgs

事件資料。

範例

下列範例顯示 將 CanExecuteRoutedEventHandler 設定 CanExecutetrue的 。

C#
void OpenCmdCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
    e.CanExecute = true;
}

備註

CanExecuteRoutedEventHandler 判斷與事件來源相關聯的命令是否能夠在命令目標上執行。 如果命令具有指定目標的命令來源,則可以透過 sender取得目標資訊。 CommandTarget如果未設定 ,則具有鍵盤焦點的專案是目標,也可以透過 sender取得。 如果判斷指令可以在目標上執行,則 CanExecuteRoutedEventArgs.CanExecute 屬性應該設定為 true,否則請將它設定為 false

您不需要依賴事件數據來判斷命令、來源和目標。 您可以將處理程式的使用限制為已知的可能命令調用,不過如果您的命令結構廣泛依賴命令路由,在事件路由中的後續潛在目標上執行相同的命令,則比較難以完成此動作。

擴充方法

GetMethodInfo(Delegate)

取得表示特定委派所代表之方法的物件。

適用於

產品 版本
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

另請參閱