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
衍生
屬性
實作

備註

Execute CanExecute的和方法不會包含命令的應用程式邏輯, 如同一般ICommand的情況, 而是這些方法會引發事件, 以遍歷專案樹狀結構來尋找具有下列專案的物件: 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.

方法會PreviewExecuted引發和Executed事件。 ExecuteThe Execute method raises the PreviewExecuted and Executed events. 方法會PreviewCanExecute引發和CanExecute事件。 CanExecuteThe CanExecute method raises the PreviewCanExecute and CanExecute events.

XAML Attribute UsageXAML 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 的淺層複本 (Shallow Copy)。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).

適用於

另請參閱