Class ObservingCommand
Describes a command that observes an object implementing INotifyPropertyChanged and listens for any changes to its property values to automatically enable or disable command execution.
Implements
Inherited Members
Namespace: TheXDS.MCART.Component
Assembly: MCART.Mvvm.dll
Syntax
public class ObservingCommand : CommandBase, ICommand
Constructors
| Edit this page View SourceObservingCommand(INotifyPropertyChanged, Action)
Initializes a new instance of ObservingCommand.
Declaration
public ObservingCommand(INotifyPropertyChanged observedSource, Action action)
Parameters
| Type | Name | Description |
|---|---|---|
| INotifyPropertyChanged | observedSource | The data source to observe. |
| Action | action | The action to execute. |
ObservingCommand(INotifyPropertyChanged, Action<object?>)
Describes a command that observes an object implementing INotifyPropertyChanged and listens for any changes to its property values to automatically enable or disable command execution.
Declaration
public ObservingCommand(INotifyPropertyChanged observedSource, Action<object?> action)
Parameters
| Type | Name | Description |
|---|---|---|
| INotifyPropertyChanged | observedSource | The data source to observe. |
| Action<object> | action | The action to execute. |
ObservingCommand(INotifyPropertyChanged, Func<object?, Task>)
Initializes a new instance of ObservingCommand.
Declaration
public ObservingCommand(INotifyPropertyChanged observedSource, Func<object?, Task> task)
Parameters
| Type | Name | Description |
|---|---|---|
| INotifyPropertyChanged | observedSource | The data source to observe. |
| Func<object, Task> | task | The asynchronous task to execute. |
ObservingCommand(INotifyPropertyChanged, Func<Task>)
Initializes a new instance of ObservingCommand.
Declaration
public ObservingCommand(INotifyPropertyChanged observedSource, Func<Task> task)
Parameters
| Type | Name | Description |
|---|---|---|
| INotifyPropertyChanged | observedSource | The data source to observe. |
| Func<Task> | task | The asynchronous task to execute. |
Properties
| Edit this page View SourceObservedProperties
Enumerates the property names being observed by this ObservingCommand.
Declaration
public IEnumerable<string> ObservedProperties { get; }
Property Value
| Type | Description |
|---|---|
| IEnumerable<string> |
ObservedSource
Reference to the data source observed by this ObservingCommand.
Declaration
public INotifyPropertyChanged ObservedSource { get; }
Property Value
| Type | Description |
|---|---|
| INotifyPropertyChanged |
Methods
| Edit this page View SourceCanExecute(object?)
Sets the method that determines whether the command can execute in its current state.
Declaration
public override bool CanExecute(object? parameter)
Parameters
| Type | Name | Description |
|---|---|---|
| object | parameter | Data used by the command. If the command does not require data, this object can be set to null. |
Returns
| Type | Description |
|---|---|
| bool |
Overrides
| Edit this page View SourceRegisterObservedProperty(Expression<Func<object?>>)
Registers a property to observe for this command using a lambda expression that selects the property.
Declaration
public ObservingCommand RegisterObservedProperty(Expression<Func<object?>> property)
Parameters
| Type | Name | Description |
|---|---|---|
| Expression<Func<object>> | property | Expression selecting the property to observe. |
Returns
| Type | Description |
|---|---|
| ObservingCommand | This same instance, allowing fluent call chaining. |
RegisterObservedProperty(params string[])
Registers one or more property names to observe for this command.
Declaration
public ObservingCommand RegisterObservedProperty(params string[] properties)
Parameters
| Type | Name | Description |
|---|---|---|
| string[] | properties | The name(s) of the property(ies) to observe. |
Returns
| Type | Description |
|---|---|
| ObservingCommand | This same instance to allow fluent usage. |
SetCanExecute(Func<bool>)
Sets the check function used to determine whether the command can execute.
Declaration
public ObservingCommand SetCanExecute(Func<bool> canExecute)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<bool> | canExecute | Function used to determine whether the command can execute. |
Returns
| Type | Description |
|---|---|
| ObservingCommand | This same instance, allowing fluent call chaining. |
SetCanExecute(Func<INotifyPropertyChanged, object?, bool>?)
Sets the check function used to determine whether the command can execute.
Declaration
public ObservingCommand SetCanExecute(Func<INotifyPropertyChanged, object?, bool>? canExecute)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<INotifyPropertyChanged, object, bool> | canExecute | Function that receives the observed source and the command parameter and returns whether the command can execute. Pass null to remove the check. |
Returns
| Type | Description |
|---|---|
| ObservingCommand | This same instance, allowing fluent call chaining. |
SetCanExecute(Func<object?, bool>)
Sets the check function used to determine whether the command can execute.
Declaration
public ObservingCommand SetCanExecute(Func<object?, bool> canExecute)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<object, bool> | canExecute | Function that receives the command parameter and returns whether the command can execute. |
Returns
| Type | Description |
|---|---|
| ObservingCommand | This same instance, allowing fluent call chaining. |
UnsetCanExecute()
Disconnects the check function used to determine whether the command can execute.
Declaration
public void UnsetCanExecute()