Class DelegateCommandBase
Namespace: Sartorius.SAF.Presentation.Commands
Assembly: Sartorius.SAF.Presentation.dll
Syntax
public abstract class DelegateCommandBase : ICommand, IActiveAware
Constructors
View SourceDelegateCommandBase(Action<Object>, Func<Object, Boolean>)
Create a new instance of a DelegateCommandBase, specifying both the execute action and the can execute function.
Declaration
protected DelegateCommandBase(Action<object> executeMethod, Func<object, bool> canExecuteMethod)
Parameters
Type | Name | Description |
---|---|---|
System.Action<System.Object> | executeMethod | The System.Action to execute when System.Windows.Input.ICommand.Execute(System.Object) is invoked. |
System.Func<System.Object, System.Boolean> | canExecuteMethod | The System.Func<T, TResult> to invoked when System.Windows.Input.ICommand.CanExecute(System.Object) is invoked. |
Properties
View SourceIsActive
Gets or sets a value indicating whether the object is active.
Declaration
public bool IsActive { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | true if the object is active; otherwise false. |
Methods
View SourceCanExecute(Object)
Determines if the command can execute with the provided parameter by invoking the System.Func<T, TResult> supplied during construction.
Declaration
protected bool CanExecute(object parameter)
Parameters
Type | Name | Description |
---|---|---|
System.Object | parameter | The parameter to use when determining if this command can execute. |
Returns
Type | Description |
---|---|
System.Boolean | Returns true if the command can execute. langword_csharp_False otherwise. |
Execute(Object)
Executes the command with the provided parameter by invoking the System.Action<T> supplied during construction.
Declaration
protected void Execute(object parameter)
Parameters
Type | Name | Description |
---|---|---|
System.Object | parameter |
OnCanExecuteChanged()
Raises System.Windows.Input.ICommand.CanExecuteChanged on the UI thread so every command invoker can re-query System.Windows.Input.ICommand.CanExecute(System.Object) to check if the command can execute.
Declaration
protected virtual void OnCanExecuteChanged()
OnIsActiveChanged()
This raises the IsActiveChanged event.
Declaration
protected virtual void OnIsActiveChanged()
RaiseCanExecuteChanged()
Raises CanExecuteChanged on the UI thread so every command invoker
can query to check if the command can execute.
Declaration
public void RaiseCanExecuteChanged()
Events
View SourceCanExecuteChanged
Occurs when changes occur that affect whether or not the command should execute. 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;
View Source
IsActiveChanged
Fired if the IsActive property changes.
Declaration
public virtual event EventHandler IsActiveChanged
Event Type
Type | Description |
---|---|
System.EventHandler |
Explicit Interface Implementations
View SourceICommand.CanExecute(Object)
Declaration
bool ICommand.CanExecute(object parameter)
Parameters
Type | Name | Description |
---|---|---|
System.Object | parameter |
Returns
Type | Description |
---|---|
System.Boolean |
ICommand.Execute(Object)
Declaration
void ICommand.Execute(object parameter)
Parameters
Type | Name | Description |
---|---|---|
System.Object | parameter |