RoutedCommand RoutedCommand RoutedCommand RoutedCommand Class

定义

定义一个实现 ICommand 并通过元素树路由的命令。Defines a command that implements ICommand and is routed through the element tree.

public ref class RoutedCommand : System::Windows::Input::ICommand
[System.ComponentModel.TypeConverter("System.Windows.Input.CommandConverter, PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, Custom=null")]
[System.ComponentModel.TypeConverter("System.Windows.Input.CommandConverter, PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, Custom=null")]
public class RoutedCommand : System.Windows.Input.ICommand
type RoutedCommand = class
    interface ICommand
Public Class RoutedCommand
Implements ICommand
继承
RoutedCommandRoutedCommandRoutedCommandRoutedCommand
派生
属性
实现

注解

在上,的CanExecute和方法不包含该命令的应用程序逻辑 (与典型ICommand相同), 但这些方法会引发事件, 这些事件遍历元素树以查找对象Execute RoutedCommandCommandBinding.The Execute and CanExecute methods on a RoutedCommand do not contain the application logic for the command as is the case with a typical ICommand, but rather, these methods raise events that traverse the element tree looking for an object with a CommandBinding. 附加到的CommandBinding事件处理程序包含命令逻辑。The event handlers attached to the CommandBinding contain the command logic.

Execute方法引发Executed和事件。 PreviewExecutedThe Execute method raises the PreviewExecuted and Executed events. CanExecute方法引发CanExecute和事件。 PreviewCanExecuteThe CanExecute method raises the PreviewCanExecute and CanExecute events.

XAML 属性用法XAML Attribute Usage

<object property="predefinedCommandName"/><object property="predefinedCommandName"/>

- 或 --or-

<object property="predefinedClassName.predefinedCommandName"/><object property="predefinedClassName.predefinedCommandName"/>

-or-

<object property="{ customClassName.customCommandName}"/><object property="{ customClassName.customCommandName}"/>

XAML 值XAML Values

predefinedClassNamepredefinedClassName
预定义的命令类之一。One of the predefined command classes.

predefinedCommandNamepredefinedCommandName
预定义的命令之一。One of the predefined commands.

customClassNamecustomClassName
一个包含自定义命令的自定义类。A custom class which contains the custom command. 自定义类通常需要xlmns前缀映射; 请参阅WPF xaml 的 XAML 命名空间和命名空间映射Custom classes generally require an xlmns prefix mapping; see XAML Namespaces and Namespace Mapping for WPF XAML.

customCommandNamecustomCommandName
自定义命令。A custom command.

构造函数

RoutedCommand() RoutedCommand() RoutedCommand() RoutedCommand()

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

RoutedCommand(String, Type) RoutedCommand(String, Type) RoutedCommand(String, Type) RoutedCommand(String, Type)

使用指定的名称和所有者类型初始化 RoutedCommand 类的新实例。Initializes a new instance of the RoutedCommand class with the specified name and owner type.

RoutedCommand(String, Type, InputGestureCollection) RoutedCommand(String, Type, InputGestureCollection) RoutedCommand(String, Type, InputGestureCollection) RoutedCommand(String, Type, InputGestureCollection)

使用指定的名称、所有者类型和笔势集合初始化 RoutedCommand 类的新实例。Initializes a new instance of the RoutedCommand class with the specified name, owner type, and collection of gestures.

属性

InputGestures InputGestures InputGestures InputGestures

获取与此命令关联的 InputGesture 对象的集合。Gets the collection of InputGesture objects that are associated with this command.

Name Name Name Name

获取命令的名称。Gets the name of the command.

OwnerType OwnerType OwnerType OwnerType

获取使用命令注册的类型。Gets the type that is registered with the command.

方法

CanExecute(Object, IInputElement) CanExecute(Object, IInputElement) CanExecute(Object, IInputElement) CanExecute(Object, IInputElement)

确定此 RoutedCommand 在其当前状态是否可以执行。Determines whether this RoutedCommand can execute in its current state.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

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

(Inherited from Object)
Execute(Object, IInputElement) Execute(Object, IInputElement) Execute(Object, IInputElement) Execute(Object, IInputElement)

对当前命令目标执行 RoutedCommandExecutes the RoutedCommand on the current command target.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

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

(Inherited from Object)
GetType() GetType() GetType() GetType()

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

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

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

(Inherited from Object)
ToString() ToString() ToString() ToString()

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

(Inherited from Object)

事件

CanExecuteChanged CanExecuteChanged CanExecuteChanged CanExecuteChanged

当命令管理器检测到对命令源所进行的更改时发生。Occurs when changes to the command source are detected by the command manager. 这些更改通常影响是否应对当前命令目标执行命令。These changes often affect whether the command should execute on the current command target.

显式界面实现

ICommand.CanExecute(Object) ICommand.CanExecute(Object) ICommand.CanExecute(Object) ICommand.CanExecute(Object)

有关此成员的说明,请参见 CanExecute(Object)For a description of this members, see CanExecute(Object).

ICommand.Execute(Object) ICommand.Execute(Object) ICommand.Execute(Object) ICommand.Execute(Object)

有关此成员的说明,请参见 Execute(Object)For a description of this members, see Execute(Object).

适用于

另请参阅