ICommandSource Interface

Definition

定义一个知道如何调用命令的对象。Defines an object that knows how to invoke a command.

public interface class ICommandSource
public interface ICommandSource
type ICommandSource = interface
Public Interface ICommandSource
Derived

Remarks

命令源定义该特定对象调用命令的方式。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. 例如,当无法对当前命令目标执行 Paste 命令时,与 Paste 命令相关联的 MenuItem 将会变灰。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.

实现 ICommandSourceWPFWPF 中的一些类包括: ButtonBaseMenuItemHyperlinkSome of the classes in WPFWPF that implement ICommandSource are: ButtonBase, MenuItem, and Hyperlink.

在 Windows Presentation Foundation 命令系统中,ICommandSource 上的 CommandTarget 属性仅在 ICommandRoutedCommand时才适用。In the Windows Presentation Foundation commanding system, the CommandTarget property on a ICommandSource is only applicable when the ICommand is a RoutedCommand. 如果 CommandTarget 是在 ICommandSource 上设置的,而相应的命令不是 RoutedCommand,则忽略命令目标。If the CommandTarget is set on a ICommandSource and the corresponding command is not a RoutedCommand, the command target is ignored.

Properties

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.

Applies to

See also