Class DelegateCommand
Provides an System.Windows.Input.ICommand implementation which relays the Execute and CanExecute method to the specified delegates.
Implements
Namespace: MAT.Atlas.Client.Presentation.Commands
Assembly: MAT.Atlas.Client.Presentation.dll
Syntax
public class DelegateCommand : Object, ICommand
Constructors
DelegateCommand()
Initializes an empty instance of the DelegateCommand class.
Declaration
protected DelegateCommand()
DelegateCommand(Action)
Initializes a new instance of the DelegateCommand class.
Declaration
public DelegateCommand(Action execute)
Parameters
Type | Name | Description |
---|---|---|
System.Action | execute | Delegate to execute when Execute is called on the command. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The execute argument must not be null. |
DelegateCommand(Action, Func<Boolean>)
Initializes a new instance of the DelegateCommand class.
Declaration
public DelegateCommand(Action execute, Func<bool> canExecute)
Parameters
Type | Name | Description |
---|---|---|
System.Action | execute | Delegate to execute when Execute is called on the command. |
System.Func<System.Boolean> | canExecute | Delegate to execute when CanExecute is called on the command. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The execute argument must not be null. |
DelegateCommand(Action, Func<Object, Boolean>)
Initializes a new instance of the DelegateCommand class.
Declaration
public DelegateCommand(Action execute, Func<object, bool> canExecute)
Parameters
Type | Name | Description |
---|---|---|
System.Action | execute | Delegate to execute when Execute is called on the command. |
System.Func<System.Object, System.Boolean> | canExecute | Delegate to execute when CanExecute is called on the command. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The execute argument must not be null. |
DelegateCommand(Action<Object>)
Initializes a new instance of the DelegateCommand class.
Declaration
public DelegateCommand(Action<object> execute)
Parameters
Type | Name | Description |
---|---|---|
System.Action<System.Object> | execute | Delegate to execute when Execute is called on the command. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The execute argument must not be null. |
DelegateCommand(Action<Object>, Func<Boolean>)
Initializes a new instance of the DelegateCommand class.
Declaration
public DelegateCommand(Action<object> execute, Func<bool> canExecute)
Parameters
Type | Name | Description |
---|---|---|
System.Action<System.Object> | execute | Delegate to execute when Execute is called on the command. |
System.Func<System.Boolean> | canExecute | Delegate to execute when CanExecute is called on the command. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The execute argument must not be null. |
DelegateCommand(Action<Object>, Func<Object, Boolean>)
Initializes a new instance of the DelegateCommand class.
Declaration
public DelegateCommand(Action<object> execute, Func<object, bool> canExecute)
Parameters
Type | Name | Description |
---|---|---|
System.Action<System.Object> | execute | Delegate to execute when Execute is called on the command. |
System.Func<System.Object, System.Boolean> | canExecute | Delegate to execute when CanExecute is called on the command. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The execute argument must not be null. |
Fields
Disabled
A DelegateCommand instance that does nothing and can never be executed.
Declaration
public static readonly DelegateCommand Disabled
Field Value
Type | Description |
---|---|
DelegateCommand |
Properties
IsEnabled
Gets or sets a value indicating whether the current DelegateCommand is enabled. If this value is not null, it takes precedence over the canExecute function was passed in the constructor. If no function was passed and this value is null the command is enabled.
Declaration
public Nullable<bool> IsEnabled { get; set; }
Property Value
Type | Description |
---|---|
System.Nullable<System.Boolean> |
Methods
CanExecute()
Convenience method that invokes CanExecute without parameters.
Declaration
public bool CanExecute()
Returns
Type | Description |
---|---|
System.Boolean | true if this command can be executed; otherwise, false. |
CanExecute(Object)
Defines the method that determines whether the command can execute in its current state.
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 this command can be executed; otherwise, false. |
Execute()
Convenience method that invokes the command without parameters.
Declaration
public void Execute()
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | The CanExecute(Object) method returns false. |
Execute(Object)
Defines the method to be called when the command is invoked.
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. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | The CanExecute(Object) method returns false. |
OnCanExecuteChanged()
Raises the CanExecuteChanged event.
Declaration
protected virtual void OnCanExecuteChanged()
RaiseCanExecuteChanged()
Raises the CanExecuteChanged event.
Declaration
public void RaiseCanExecuteChanged()
Events
CanExecuteChanged
Occurs when changes occur that affect whether or not the command should execute.
Declaration
public event EventHandler CanExecuteChanged
Event Type
Type | Description |
---|---|
System.EventHandler |