ICommandSource 介面

定義

定義知道如何叫用命令的物件。Defines an object that knows how to invoke a command.

public interface class ICommandSource
public interface ICommandSource
type ICommandSource = interface
Public Interface ICommandSource
衍生

備註

命令來源會定義該特定物件叫用命令的方式。The command source defines how a command is invoked by that particular object. 例如, 如果Button與命令相關聯, Button當按一下時, 就會叫用命令。For example, if a Button is associated with a command, the command is invoked when the Button is clicked.

如果與相關聯的命令無法在目前的命令目標上執行, 則命令來源通常會自行停用。A command source will normally disable itself if the command it is associated with cannot execute on the current command target. 例如, 當MenuItem Paste命令無法在目前Paste的命令目標上執行時, 與命令相關聯的會變成灰色。For example, a MenuItem associated with the Paste command will gray itself out when the Paste command cannot execute on the current command target.

一般來說, 命令來源會接聽命令上的CanExecuteChanged事件。Normally, a command source will listen to the CanExecuteChanged event on the command. 這會在命令目標上的條件變更時通知命令來源, 例如失去鍵盤焦點。This informs the command source when conditions change on the command target, such as loss of keyboard focus. 接著, 命令來源可以使用CanExecute方法來查詢命令。The command source can then query the command using the CanExecute method.

WPFWPF ButtonBase MenuItem Hyperlink該實作為中的部分類別包括:、和。ICommandSourceSome of the classes in WPFWPF that implement ICommandSource are: ButtonBase, MenuItem, and Hyperlink.

在 Windows Presentation Foundation CommandTarget命令系統中, 中的屬性ICommandSource只有在ICommand是時才RoutedCommand適用。In the Windows Presentation Foundation commanding system, the CommandTarget property on a ICommandSource is only applicable when the ICommand is a RoutedCommand. 如果在上設定, RoutedCommand而且對應的命令不是,則會忽略命令目標。ICommandSource CommandTargetIf the CommandTarget is set on a ICommandSource and the corresponding command is not a RoutedCommand, the command target is ignored.

屬性

Command

取得叫用命令來源時,將會執行的命令。Gets the command that will be executed when the command source is invoked.

CommandParameter

表示使用者定義的資料值,可以在執行時傳遞至命令。Represents a user defined data value that can be passed to the command when it is executed.

CommandTarget

正在其上執行命令的物件。The object that the command is being executed on.

適用於

另請參閱