Class ExceptionHandlingRelayCommand
A relay command that handles exceptions by showing them to the user. This class wraps an existing action and executes it when the command is invoked. If the action throws an exception, the exception is caught and is shown via IMessageManager.ShowMessage().
Inherited Members
Namespace: Benday.Presentation
Assembly: Benday.Presentation.Core.dll
Syntax
public class ExceptionHandlingRelayCommand : IRelayCommand, ICommand
Constructors
| Edit this page View SourceExceptionHandlingRelayCommand(IMessageManager, Action)
Creates a new instance of the ExceptionHandlingRelayCommand class.
Declaration
public ExceptionHandlingRelayCommand(IMessageManager msgManager, Action execute)
Parameters
| Type | Name | Description |
|---|---|---|
| IMessageManager | msgManager | Instance of IMessageManager to use |
| Action | execute | The action to perform |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
ExceptionHandlingRelayCommand(IMessageManager, Action, Func<bool>?)
Creates a new instance of the ExceptionHandlingRelayCommand class that can be enabled and disabled.
Declaration
public ExceptionHandlingRelayCommand(IMessageManager msgManager, Action execute, Func<bool>? canExecute)
Parameters
| Type | Name | Description |
|---|---|---|
| IMessageManager | msgManager | Instance of IMessageManager to use |
| Action | execute | The action to perform |
| Func<bool> | canExecute | Returns true when the command can run. Call NotifyCanExecuteChanged() when the answer changes. Null means always. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
Methods
| Edit this page View SourceCanExecute(object?)
Returns true if the command can be executed.
Declaration
public bool CanExecute(object? parameter)
Parameters
| Type | Name | Description |
|---|---|---|
| object | parameter |
Returns
| Type | Description |
|---|---|
| bool | The result of the canExecute function, or true when none was supplied. |
Execute(object?)
Executes the action and handles any exceptions by showing them to the user.
Declaration
public void Execute(object? parameter)
Parameters
| Type | Name | Description |
|---|---|---|
| object | parameter |
NotifyCanExecuteChanged()
Raises CanExecuteChanged.
Declaration
public void NotifyCanExecuteChanged()
Events
| Edit this page View SourceCanExecuteChanged
Raised by NotifyCanExecuteChanged() to tell the view to ask CanExecute again.
Declaration
public event EventHandler? CanExecuteChanged
Event Type
| Type | Description |
|---|---|
| EventHandler |