RoutedCommand Class

Definition

定义一个实现 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")]
public class RoutedCommand : System.Windows.Input.ICommand
[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
Inheritance
RoutedCommand
Derived
Attributes
Implements

Remarks

RoutedCommand 上的 ExecuteCanExecute 方法不包含与典型 ICommand相同的命令的应用程序逻辑,但这两种方法会引发事件,这些事件遍历元素树,以便查找使用 CommandBinding的对象。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 方法引发 PreviewExecutedExecuted 事件。The Execute method raises the PreviewExecuted and Executed events. CanExecute 方法引发 PreviewCanExecuteCanExecute 事件。The CanExecute method raises the PreviewCanExecute and CanExecute events.

XAML 特性用法XAML Attribute Usage

<对象**属性= "predefinedCommandName"/><object property="predefinedCommandName"/>

- 或 --or-

<对象**属性= "predefinedClassName"。predefinedCommandName"/><object property="predefinedClassName.predefinedCommandName"/>

- 或 --or-

<对象**属性= "{ customClassNamecustomCommandName} "/><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.

Constructors

RoutedCommand()

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

RoutedCommand(String, Type)

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

RoutedCommand(String, Type, InputGestureCollection)

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

Properties

InputGestures

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

Name

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

OwnerType

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

Methods

CanExecute(Object, IInputElement)

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

Equals(Object)

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

(Inherited from Object)
Execute(Object, IInputElement)

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

GetHashCode()

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

(Inherited from Object)
GetType()

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

(Inherited from Object)
MemberwiseClone()

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

(Inherited from Object)
ToString()

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

(Inherited from Object)

Events

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.

Explicit Interface Implementations

ICommand.CanExecute(Object)

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

ICommand.Execute(Object)

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

Applies to

See also