Show / Hide Table of Contents

Class CompositeCommand

The CompositeCommand composes one or more ICommands.

Inheritance
System.Object
CompositeCommand
Implements
System.Windows.Input.ICommand
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Sartorius.SAF.Presentation.Commands
Assembly: Sartorius.SAF.Presentation.dll
Syntax
public class CompositeCommand : ICommand

Constructors

View Source

CompositeCommand()

Initializes a new instance of CompositeCommand.

Declaration
public CompositeCommand()
View Source

CompositeCommand(Boolean)

Initializes a new instance of CompositeCommand.

Declaration
public CompositeCommand(bool monitorCommandActivity)
Parameters
Type Name Description
System.Boolean monitorCommandActivity

Indicates when the command activity is going to be monitored.

Properties

View Source

RegisteredCommands

Gets the list of all the registered commands.

Declaration
public IList<ICommand> RegisteredCommands { get; }
Property Value
Type Description
System.Collections.Generic.IList<System.Windows.Input.ICommand>

A list of registered commands.

Remarks

This returns a copy of the commands subscribed to the CompositeCommand.

Methods

View Source

CanExecute(Object)

Forwards System.Windows.Input.ICommand.CanExecute(System.Object) to the registered commands and returns true if all of the commands return true.

Declaration
public virtual bool CanExecute(object parameter)
Parameters
Type Name Description
System.Object parameter

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

Returns
Type Description
System.Boolean

true if all of the commands return true; otherwise, false.

View Source

Execute(Object)

Forwards System.Windows.Input.ICommand.Execute(System.Object) to the registered commands.

Declaration
public virtual void Execute(object parameter)
Parameters
Type Name Description
System.Object parameter

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

View Source

OnCanExecuteChanged()

Raises System.Windows.Input.ICommand.CanExecuteChanged on the UI thread so every command invoker can query System.Windows.Input.ICommand.CanExecute(System.Object) to check if the CompositeCommand can execute.

Declaration
protected virtual void OnCanExecuteChanged()
View Source

RegisterCommand(ICommand)

Adds a command to the collection and signs up for the System.Windows.Input.ICommand.CanExecuteChanged event of it.

Declaration
public virtual void RegisterCommand(ICommand command)
Parameters
Type Name Description
System.Windows.Input.ICommand command

The command to register.

Remarks

If this command is set to monitor command activity, and command implements the IActiveAware interface, this method will subscribe to its IsActiveChanged event.

View Source

ShouldExecute(ICommand)

Evaluates if a command should execute.

Declaration
protected virtual bool ShouldExecute(ICommand command)
Parameters
Type Name Description
System.Windows.Input.ICommand command

The command to evaluate.

Returns
Type Description
System.Boolean

A System.Boolean value indicating whether the command should be used when evaluating CanExecute(Object) and Execute(Object).

Remarks

If this command is set to monitor command activity, and command implements the IActiveAware interface, this method will return false if the command's IsActive property is false; otherwise it always returns true.

View Source

UnregisterCommand(ICommand)

Removes a command from the collection and removes itself from the System.Windows.Input.ICommand.CanExecuteChanged event of it.

Declaration
public virtual void UnregisterCommand(ICommand command)
Parameters
Type Name Description
System.Windows.Input.ICommand command

The command to unregistered.

Events

View Source

CanExecuteChanged

Occurs when any of the registered commands raise System.Windows.Input.ICommand.CanExecuteChanged. You must keep a hard reference to the handler to avoid garbage collection and unexpected results. See remarks for more information.

Declaration
public event EventHandler CanExecuteChanged
Event Type
Type Description
System.EventHandler
Remarks

When subscribing to the System.Windows.Input.ICommand.CanExecuteChanged event using code (not when binding using XAML) will need to keep a hard reference to the event handler. This is to prevent garbage collection of the event handler because the command implements the Weak Event pattern so it does not have a hard reference to this handler. An example implementation can be seen in the CompositeCommand and CommandBehaviorBase classes. In most scenarios, there is no reason to sign up to the CanExecuteChanged event directly, but if you do, you are responsible for maintaining the reference.

Examples

The following code holds a reference to the event handler. The myEventHandlerReference value should be stored in an instance member to avoid it from being garbage collected.

EventHandler myEventHandlerReference = new EventHandler(this.OnCanExecuteChanged);
command.CanExecuteChanged += myEventHandlerReference;

Implements

System.Windows.Input.ICommand

Extension Methods

CollectionExtensions.AddRange<T, TCollection>(TCollection, IEnumerable<T>)
SerializableObjectCloneExtension.Clone<T>(T)
  • View Source
Back to top Generated by DocFX