CompositeCommand Class
public class CompositeCommand
- Inheritance:
- object object
- Derived:
- PreviewableCompositeCommand
Constructors
CompositeCommand()
Initializes an instance of the 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
- bool:
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 istrue
.
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 |
Returns
- bool:
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 |
GetEnabledCommandsForExecution(object?)
Returns the collection 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 |
Returns
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
- bool:
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
- bool:
true
if the command was successfully unregistered; otherwise,false
.
See Also
Events
CanExecuteChanged
Occurs when changes occur that affect whether or not the command should execute.
Inherited Members
- object.GetType()
- object.MemberwiseClone()
- object.ToString()
- object.Equals(object)
- object.Equals(object, object)
- object.ReferenceEquals(object, object)
- object.GetHashCode()