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.

Execute 呼叫的或 CanExecute 方法時 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 for 命令的,則會呼叫適當的處理常式。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. 這是因為會將命令系結 CommandBindingExecutedRoutedEventHandler ,以及 CanExecuteRoutedEventHandler 接聽 ExecutedCanExecute 路由事件(當呼叫的和方法時引發 ExecuteCanExecute 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

取得或設定與這個 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.

適用於

另請參閱