In This Article

CompositeCommand Class

Defines a single ICommand that is a collection of multiple ICommand instances acting together.

public class CompositeCommand : ICommand
Inheritance:
Object Object
Derived:
PreviewableCompositeCommand

Constructors

CompositeCommand()

Initializes an instance of the CompositeCommand class.

public CompositeCommand()

Properties

RequireAllCommandsCanExecute

Gets or sets if all registered commands must support execution for the composite command to support execution.

public bool RequireAllCommandsCanExecute { get; set; }

Property Value

Boolean:

true if all registered commands must be enabled for the composite command to support execution. false if only a single command must be enabled for the composite command to support execution. The default value is true.

Methods

CanExecute(Object)

Tests if one or more of the registered commands can execute in the current state.

public bool CanExecute(object parameter)
Parameter Type Description
parameter Object

Data used by the command. If the command does not require data to be passed, this object can be set to null.

Returns

Boolean:

true if the command can be executed; otherwise, false.

Remarks

When RequireAllCommandsCanExecute is true, all registered commands must return true from their own CanExecute(Object) method with the same parameter for this composite command to also return true. When RequireAllCommandsCanExecute is false, only a single command must return true.

Execute(Object)

Executes each registered command if the CanExecute(Object) method with the same parameter returns true.

public void Execute(object parameter)
Parameter Type Description
parameter Object

Data used by the command. If the command does not require data to be passed, this object can be set to null.

GetEnabledCommandsForExecution(Object)

Returns the colection of commands that are enabled for execution.

protected IList<ICommand> GetEnabledCommandsForExecution(object parameter)
Parameter Type Description
parameter Object

Data used by the command. If the command does not require data to be passed, this object can be set to null.

Returns

IList<ICommand>:

The colection of commands that are enabled for execution.

NotifyCanExecuteChanged()

Raises the CanExecuteChanged event.

protected virtual void NotifyCanExecuteChanged()

OnCommandRegistered(ICommand)

This method is called when a command is successfully registered.

protected virtual void OnCommandRegistered(ICommand command)
Parameter Type Description
command ICommand

The registered command.

OnCommandUnregistered(ICommand)

This method is called when a command is successfully unregistered.

protected virtual void OnCommandUnregistered(ICommand command)
Parameter Type Description
command ICommand

The unregistered command.

OnRegisteredCommandCanExecuteChanged(Object, EventArgs)

This method is called when the CanExecuteChanged event is raised from a registered command.

protected virtual void OnRegisteredCommandCanExecuteChanged(object sender, EventArgs e)
Parameter Type Description
sender Object

The sender of the event.

e EventArgs

The EventArgs for the event.

RegisterCommand(ICommand)

Registers a command for participation with this composite command.

public void RegisterCommand(ICommand command)
Parameter Type Description
command ICommand

The command to be registered.

See Also

TryRegisterCommand(ICommand)

Tries to register a command for participation with this composite command.

public bool TryRegisterCommand(ICommand command)
Parameter Type Description
command ICommand

The command to register.

Returns

Boolean:

true if the command was successfully registered; otherwise, false.

See Also

UnregisterCommand(ICommand)

Unregisters a previously registered command to stop participating in this composite command.

public bool UnregisterCommand(ICommand command)
Parameter Type Description
command ICommand

The command to unregister.

Returns

Boolean:

true if the command was successfully unregistered; otherwise, false.

See Also

Events

CanExecuteChanged

public event EventHandler CanExecuteChanged

Event Type

EventHandler

Inherited Members