Command 類別

定義

定義可包裝 ActionICommand 實作。

public class Command : System.Windows.Input.ICommand
type Command = class
    interface ICommand
繼承
Command
衍生
實作

備註

下列範例會建立新的 Command,並將其設定為按鈕。

var command = new Command (() => Debug.WriteLine ("Command executed"));
var button = new Button {
  Text = "Hit me to execute the command",
  Command = command,
};

更實用的案例會採用 參數

var command = new Command (o => Debug.WriteLine ("Command executed: {0}", o));
var button = new Button {
  Text = "Hit me to execute the command",
  Command = command,
  CommandParameter = "button0",
};

建構函式

Command(Action)

初始化 Command 類別的新執行個體。

Command(Action, Func<Boolean>)

初始化 Command 類別的新執行個體。

Command(Action<Object>)

初始化 Command 類別的新執行個體。

Command(Action<Object>, Func<Object,Boolean>)

初始化 Command 類別的新執行個體。

方法

CanExecute(Object)

傳回 Boolean,指出是否可以使用指定的參數來執行 Command。

ChangeCanExecute()

傳送 CanExecuteChanged

Execute(Object)

叫用 execute Action

事件

CanExecuteChanged

發生於 Command 目標應該重新評估是否可執行 Command 時。

適用於