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 / Executed PreviewCanExecute / CanExecute 实现和确定命令状态的和事件关联。A CommandBinding associates a command with the PreviewExecuted/Executed and PreviewCanExecute/CanExecute events which implement and determine the status of the command.

调用的 ExecuteCanExecute 方法时 RoutedCommand ,将 PreviewExecuted / Executed PreviewCanExecute / CanExecute 在命令目标上引发或事件。When 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 用于命令的,则会通过元素树路由事件,直到找到具有的元素 CommandBindingIf 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与不是的使用有限 ICommand RoutedCommandA CommandBinding has limited use with an ICommand that is not a RoutedCommand. 这是因为,将 CommandBinding 命令绑定到和, ExecutedRoutedEventHandler 后者会 CanExecuteRoutedEventHandler 侦听 Executed 和路由事件,这些 CanExecute 事件是在调用的 Execute 和方法时引发的 CanExecute RoutedCommandThis 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

获取或设置与此 CommandBinding 关联的 ICommandGets 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.

适用于

另请参阅