ICommandBinding Interface

Represents a binding for a command.

Definition

Namespace: KGySoft.ComponentModel
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 9.0.0-preview.1
C#
public interface ICommandBinding : IDisposable
Implements
IDisposable

Remarks

Whereas an ICommand is a static logic without state, the created binding is a dynamic entity: it has a state, which can store variable elements (see ICommandState), and has sources and targets, which can be added and removed during the lifetime of the binding.

The binding should be disposed when it is not used anymore so it releases the events it used internally. If more bindings are used it is recommended to create them by a CommandBindingsCollection instance so when it is disposed it releases all of the added bindings at once.

  Tip

See the Remarks section of the ICommand interface for details and examples about commands.

Properties

IsDisposed Gets whether this ICommandBinding instance is disposed.
Sources Gets a copy of the sources of this ICommandBinding along with the bound event names.
State Gets the managed set of states of this ICommandBinding instance. Whenever a new source is added or an entry of the returned ICommandState is changed, and at least one ICommandStateUpdater is added to this ICommandBinding, then the entries are applied for all of the sources of the binding.
See the Remarks section of the ICommandState interface for details.
StateUpdaters Gets a copy of the state updaters of this ICommandBinding.
Targets Gets a copy of the targets of this ICommandBinding.

Methods

AddSource Adds a source to this ICommandBinding instance. For static events pass a Type as source. If state updaters were added to the binding by the AddStateUpdater method, then the State entries will be applied to the new source. At least one source has to be added to the binding to be able to invoke the underlying ICommand.
AddStateUpdater Adds a state updater to the binding. If at least one updater is added, then changing the entries of the State property will be applied on all added sources.
See the Remarks section of the ICommandStateUpdater interface for details.
AddTarget(FuncObject) Adds a target getter function to this ICommandBinding instance. Whenever the underlying ICommand executes it will evaluate the specified getter delegate.
AddTarget(Object) Adds the target to this ICommandBinding instance. The underlying ICommand will be invoked for each added target. If no targets are added the command will be invoked with a target.
InvokeCommand Invokes the underlying ICommand for all of the added targets using the specified source, event name, event arguments and parameters.
RemoveSource Removes the specified source from this ICommandBinding instance. The used events of the removed source will be released.
RemoveStateUpdater Removes the specified state updater. The removed updater will not be disposed.
RemoveTarget Removes the specified target from this ICommandBinding instance.
WithParameter Specifies a callback to obtain the command parameter value for the underlying ICommand. It is evaluated once whenever a source event is triggered. If this ICommandBinding has multiple targets, the ICommand.Execute method is invoked with the same parameter value for each target.

Events

Error Occurs when an exception is thrown during the command execution. The Error property returns the Exception, which is about to be thrown, and the Context property gets a hint about the source of the error. You can set the Handled property to to suppress the error, but critical exceptions (OutOfMemoryException, StackOverflowException) cannot be handled by this event.
Executed Occurs when the associated ICommand has been executed.
Executing Occurs when the associated ICommand is about to be executed. Command states, including the Enabled state still can be adjusted here.

See Also