ICommand 介面

定義

定義命令。

public interface class ICommand
public interface ICommand
[System.ComponentModel.TypeConverter("System.Windows.Input.CommandConverter, PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, Custom=null")]
public interface ICommand
[System.ComponentModel.TypeConverter("System.Windows.Input.CommandConverter, PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, Custom=null")]
public interface ICommand
type ICommand = interface
[<System.ComponentModel.TypeConverter("System.Windows.Input.CommandConverter, PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, Custom=null")>]
type ICommand = interface
[<System.ComponentModel.TypeConverter("System.Windows.Input.CommandConverter, PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, Custom=null")>]
type ICommand = interface
Public Interface ICommand
衍生
屬性

備註

RoutedCommandRoutedUICommand 是 #DEDFF8D4A0FD84593BA2DA13288ED3905 (WPF) 中介面的ICommand兩個實作。

Windows 執行階段 應用程式中的 ICommand

介面ICommand是在 .NET 中針對 Windows 執行階段 應用程式撰寫之命令的程式代碼合約。 這些命令提供 UI 元素的命令行為,例如 Windows 執行階段 XAMLButton,特別是 AppBarButton。 如果您要定義 Windows 執行階段 應用程式的命令,您基本上會使用相同的技術來定義 .NET 應用程式的命令。 定義實作 並特別實作 方法的Execute類別,ICommand以實作 命令。

Windows 執行階段 的 XAML 不支援 x:Static,因此,如果命令是從 Windows 執行階段 XAML 使用,請勿嘗試使用x:Static標記延伸。 此外,Windows 執行階段 沒有任何預先定義的命令連結庫,因此此處所示的 XAML 語法並不適用於您實作 介面並定義命令以使用 Windows 執行階段 用法的情況。

XAML 屬性用法

<object-property="predefined-command-name"/>
-or-
<object-property="predefined-class-name.predefined-command-name"/>
-or-
<object-property="{custom-class-name.custom-command-name}"/>

XAML 值

predefined-class-name
其中一個預先定義的命令類別。

predefined-command-name
其中一個預先定義的命令。

custom-class-name
包含自訂命令的自定義類別。 自定義類別通常需要前置 xlmns 詞對應。 如需詳細資訊,請參閱 WPF XAML 的 XAML 命名空間和命名空間對應

custom-command-name
自訂命令。

方法

CanExecute(Object)

判斷命令是否可以在其目前狀態中執行。

Execute(Object)

定義叫用命令時要呼叫的方法。

事件

CanExecuteChanged

發生於會影響命令是否應該執行的變更時。

適用於