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/ExecutedPreviewCanExecute/會執行並判斷命令狀態的事件產生關聯。CanExecuteA CommandBinding associates a command with the PreviewExecuted/Executed and PreviewCanExecute/CanExecute events which implement and determine the status of the command.

呼叫 RoutedCommandExecuteCanExecute 方法時,會在命令目標上引發 PreviewExecuted/ExecutedPreviewCanExecute/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,則會透過專案樹狀結構來路由事件,直到找到具有 CommandBinding 的元素為止。If 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 與不是 RoutedCommandICommand 使用限制。A CommandBinding has limited use with an ICommand that is not a RoutedCommand. 這是因為 CommandBinding 會將命令系結至 ExecutedRoutedEventHandler 以及接聽 ExecutedCanExecuteRoutedEventHandler,並 CanExecute 呼叫 ExecuteCanExecuteRoutedCommand 方法時引發的路由事件。This 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.

適用於

另請參閱