Bewerken

Share via


CommandBinding Class

Definition

Binds a RoutedCommand to the event handlers that implement the command.

public ref class CommandBinding
public class CommandBinding
type CommandBinding = class
Public Class CommandBinding
Inheritance
CommandBinding

Remarks

A CommandBinding associates a command with the PreviewExecuted/Executed and PreviewCanExecute/CanExecute events which implement and determine the status of the command.

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. If the command target has a CommandBinding for the command, the appropriate handlers are called. 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.

A CommandBinding has limited use with an ICommand that is not a RoutedCommand. 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.

Constructors

CommandBinding()

Initializes a new instance of the CommandBinding class.

CommandBinding(ICommand, ExecutedRoutedEventHandler, CanExecuteRoutedEventHandler)

Initializes a new instance of the CommandBinding class by using the specified ICommand and the specified Executed and CanExecute event handlers.

CommandBinding(ICommand, ExecutedRoutedEventHandler)

Initializes a new instance of the CommandBinding class by using the specified ICommand and the specified Executed event handler.

CommandBinding(ICommand)

Initializes a new instance of the CommandBinding class by using the specified ICommand.

Properties

Command

Gets or sets the ICommand associated with this CommandBinding.

Methods

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

Events

CanExecute

Occurs when the command associated with this CommandBinding initiates a check to determine whether the command can be executed on the command target.

Executed

Occurs when the command associated with this CommandBinding executes.

PreviewCanExecute

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

Occurs when the command associated with this CommandBinding executes.

Applies to

See also