ICommandBinding Interface

KGy SOFT Core Libraries Help
Represents a binding for a command.
See the Remarks section for details.

Namespace:  KGySoft.ComponentModel
Assembly:  KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 6.0.0

public interface ICommandBinding : IDisposable

The ICommandBinding type exposes the following members.


Public propertyIsDisposed
Gets whether this ICommandBinding instance is disposed.
Public propertySources
Gets a copy of the sources of this ICommandBinding along with the bound event names.
Public propertyState
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 if the ICommandState interface for details.
Public propertyStateUpdaters
Gets a copy of the state updaters of this ICommandBinding.
Public propertyTargets
Gets a copy of the targets of this ICommandBinding.

Public methodAddSource
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.
Public methodAddStateUpdater
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.
Public methodAddTarget(FuncObject)
Adds a target getter function to this ICommandBinding instance. Whenever the underlying ICommand executes it will evaluate the specified getter delegate.
Public methodAddTarget(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.
Public methodInvokeCommand
Invokes the underlying ICommand for all of the added targets using the specified source, event name, event arguments and parameters.
Public methodRemoveSource
Removes the specified source from this ICommandBinding instance. The used events of the removed source will be released.
Public methodRemoveStateUpdater
Removes the specified state updater. The removed updater will not be disposed.
Public methodRemoveTarget
Removes the specified target from this ICommandBinding instance.
Public methodWithParameter
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.

Public eventError
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.
Public eventExecuted
Occurs when the associated ICommand has been executed.
Public eventExecuting
Occurs when the associated ICommand is about to be executed. Command states, including the Enabled state still can be adjusted here.

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 Tip
See the Remarks section of the ICommand interface for details and examples about commands.
See Also