ICommand 介面
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
定義命令。
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
- 衍生
- 屬性
RoutedCommand和 RoutedUICommand 是 #DEDFF8D4A0FD84593BA2DA13288ED3905 (WPF) 中介面的ICommand兩個實作。
介面ICommand是在 .NET 中針對 Windows 執行階段 應用程式撰寫之命令的程式代碼合約。 這些命令提供 UI 元素的命令行為,例如 Windows 執行階段 XAMLButton
,特別是 AppBarButton
。 如果您要定義 Windows 執行階段 應用程式的命令,您基本上會使用相同的技術來定義 .NET 應用程式的命令。 定義實作 並特別實作 方法的Execute類別,ICommand以實作 命令。
Windows 執行階段 的 XAML 不支援 x:Static
,因此,如果命令是從 Windows 執行階段 XAML 使用,請勿嘗試使用x:Static
標記延伸。 此外,Windows 執行階段 沒有任何預先定義的命令連結庫,因此此處所示的 XAML 語法並不適用於您實作 介面並定義命令以使用 Windows 執行階段 用法的情況。
<object-property="predefined-command-name"/>
-or-
<object-property="predefined-class-name.predefined-command-name"/>
-or-
<object-property="{custom-class-name.custom-command-name}"/>
predefined-class-name
其中一個預先定義的命令類別。
predefined-command-name
其中一個預先定義的命令。
custom-class-name
包含自訂命令的自定義類別。 自定義類別通常需要前置 xlmns
詞對應。 如需詳細資訊,請參閱 WPF XAML 的 XAML 命名空間和命名空間對應。
custom-command-name
自訂命令。
Can |
判斷命令是否可以在其目前狀態中執行。 |
Execute(Object) |
定義叫用命令時要呼叫的方法。 |
Can |
發生於會影響命令是否應該執行的變更時。 |
產品 | 版本 |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.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 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |