CommandBinding 类

定义

RoutedCommand 绑定到实现该命令的事件处理程序。Binds a RoutedCommand to the event handlers that implement the command.

public ref class CommandBinding
public class CommandBinding
type CommandBinding = class
Public Class CommandBinding
继承
CommandBinding

注解

CommandBinding 将命令与 PreviewExecuted/ExecutedPreviewCanExecute/实现和确定命令状态的事件进行关联。CanExecuteA CommandBinding associates a command with the PreviewExecuted/Executed and PreviewCanExecute/CanExecute events which implement and determine the status of the command.

当调用 RoutedCommandExecuteCanExecute 方法时,会在命令目标上引发 PreviewExecuted/ExecutedPreviewCanExecute/事件。CanExecuteWhen the Execute or CanExecute method of a RoutedCommand is called, the PreviewExecuted/Executed or the PreviewCanExecute/CanExecute events are raised on the command target. 如果命令目标具有该命令的 CommandBinding,则将调用相应的处理程序。If the command target has a CommandBinding for the command, the appropriate handlers are called. 如果命令目标没有命令的 CommandBinding,则会通过元素树路由事件,直到找到具有 CommandBinding 的元素。If the command target does not have a CommandBinding for the command, the events are routed through the element tree until an element that has a CommandBinding is found.

CommandBinding 与不是 RoutedCommandICommand 的使用有限。A CommandBinding has limited use with an ICommand that is not a RoutedCommand. 这是因为 CommandBinding 会将命令绑定到 ExecutedRoutedEventHandlerCanExecuteRoutedEventHandler 侦听 ExecutedCanExecute 路由事件,这些事件是在调用 ExecuteCanExecuteRoutedCommand 方法时引发的。This is because a CommandBinding binds the command to the ExecutedRoutedEventHandler and the CanExecuteRoutedEventHandler which listen to the Executed and CanExecute routed events which are raised when the Execute and CanExecute method of the RoutedCommand are called.

构造函数

CommandBinding()

初始化 CommandBinding 类的新实例。Initializes a new instance of the CommandBinding class.

CommandBinding(ICommand)

使用指定的 CommandBinding 初始化 ICommand 类的新实例。Initializes a new instance of the CommandBinding class by using the specified ICommand.

CommandBinding(ICommand, ExecutedRoutedEventHandler)

使用指定的 CommandBinding 和指定的 ICommand 事件处理程序初始化 Executed 类的新实例。Initializes a new instance of the CommandBinding class by using the specified ICommand and the specified Executed event handler.

CommandBinding(ICommand, ExecutedRoutedEventHandler, CanExecuteRoutedEventHandler)

使用指定的 CommandBinding 和指定的 ICommandExecuted 事件处理程序初始化 CanExecute 类的新实例。Initializes a new instance of the CommandBinding class by using the specified ICommand and the specified Executed and CanExecute event handlers.

属性

Command

获取或设置与此 ICommand 关联的 CommandBindingGets or sets the ICommand associated with this CommandBinding.

方法

Equals(Object)

确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

事件

CanExecute

在与此 CommandBinding 关联的命令开始检查能否对命令目标执行该命令时发生。Occurs when the command associated with this CommandBinding initiates a check to determine whether the command can be executed on the command target.

Executed

执行与此 CommandBinding 相关联的命令时发生。Occurs when the command associated with this CommandBinding executes.

PreviewCanExecute

在与此 CommandBinding 关联的命令开始检查能否对当前命令目标执行该命令时发生。Occurs when the command associated with this CommandBinding initiates a check to determine whether the command can be executed on the current command target.

PreviewExecuted

执行与此 CommandBinding 相关联的命令时发生。Occurs when the command associated with this CommandBinding executes.

适用于

另请参阅