Class ViewModelBase
Base class for creating ViewModels.
Inheritance
Inherited Members
Namespace: TheXDS.MCART.Types.Base
Assembly: MCART.Mvvm.dll
Syntax
public abstract class ViewModelBase : NotifyPropertyChanged, INotifyPropertyChangeBase, IRefreshable, INotifyPropertyChanged
Constructors
| Edit this page View SourceViewModelBase()
Initializes a new instance of the ViewModelBase class.
Declaration
protected ViewModelBase()
Properties
| Edit this page View SourceIsBusy
Gets a value indicating whether this ViewModelBase is busy.
Declaration
public bool IsBusy { get; protected set; }
Property Value
| Type | Description |
|---|---|
| bool |
Methods
| Edit this page View SourceBusyOp(Action)
Executes an action while automatically managing the 'busy' state of this ViewModel.
Declaration
protected void BusyOp(Action action)
Parameters
| Type | Name | Description |
|---|---|---|
| Action | action | Action to execute. |
BusyOp(Task)
Executes a task while automatically managing the 'busy' state of this ViewModel.
Declaration
protected Task BusyOp(Task task)
Parameters
| Type | Name | Description |
|---|---|---|
| Task | task | Task to execute. |
Returns
| Type | Description |
|---|---|
| Task | A Task that can be awaited to monitor the async operation. |
BusyOp<T>(Func<T>)
Executes a function while automatically managing the 'busy' state of this ViewModel.
Declaration
protected T BusyOp<T>(Func<T> function)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<T> | function | Function to execute. |
Returns
| Type | Description |
|---|---|
| T | The result returned by the specified function. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of the function result. |
BusyOp<T>(Task<T>)
Executes a task that returns a result while automatically managing the 'busy' state of this ViewModel.
Declaration
protected Task<T> BusyOp<T>(Task<T> task)
Parameters
| Type | Name | Description |
|---|---|---|
| Task<T> | task | Task to execute. |
Returns
| Type | Description |
|---|---|
| Task<T> | A Task<TResult> that can be awaited to monitor the async operation. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of the task result. |
~ViewModelBase()
Finalizes this instance of the ViewModelBase class.
Declaration
protected ~ViewModelBase()
Observe(Expression<Func<object?>>[], Action)
Registers properties with change notification to be observed and handled by the specified delegate.
Declaration
protected void Observe(Expression<Func<object?>>[] propertySelectors, Action handler)
Parameters
| Type | Name | Description |
|---|---|---|
| Expression<Func<object>>[] | propertySelectors | Selector functions for the properties to observe. |
| Action | handler | Delegate to invoke when any of the properties has changed. |
Exceptions
| Type | Condition |
|---|---|
| InvalidArgumentException | Thrown if a property selector did not select a valid member on the instance to configure. |
| ArgumentNullException | Thrown if |
| EmptyCollectionException | Thrown if |
Observe(string, Action)
Registers a property with change notification to be observed and handled by the specified delegate.
Declaration
protected void Observe(string propertyName, Action handler)
Parameters
| Type | Name | Description |
|---|---|---|
| string | propertyName | Name of the property to observe. |
| Action | handler | Delegate to invoke when the property has changed. |
Exceptions
| Type | Condition |
|---|---|
| InvalidArgumentException | Thrown if |
| ArgumentNullException | Thrown if |
Observe(string[], Action)
Registers properties with change notification to be observed and handled by the specified delegate.
Declaration
protected void Observe(string[] propertyNames, Action handler)
Parameters
| Type | Name | Description |
|---|---|---|
| string[] | propertyNames | Names of the properties to observe. |
| Action | handler | Delegate to invoke when any of the properties has changed. |
Exceptions
| Type | Condition |
|---|---|
| InvalidArgumentException | Thrown if any element of |
| ArgumentNullException | Thrown if |
ObserveFrom(INotifyPropertyChanged, PropertyInfo, Action)
Registers a property with change notification to be observed and handled by the specified delegate.
Declaration
protected void ObserveFrom(INotifyPropertyChanged source, PropertyInfo property, Action handler)
Parameters
| Type | Name | Description |
|---|---|---|
| INotifyPropertyChanged | source | Observed source. |
| PropertyInfo | property | Property to observe. |
| Action | handler | Delegate to invoke when the property has changed. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if |
ObserveFrom<T>(T, Expression<Func<T, object?>>, Action)
Registers a property with change notification to be observed and handled by the specified delegate.
Declaration
protected void ObserveFrom<T>(T source, Expression<Func<T, object?>> propertySelector, Action handler) where T : notnull, INotifyPropertyChanged
Parameters
| Type | Name | Description |
|---|---|---|
| T | source | Observed source. |
| Expression<Func<T, object>> | propertySelector | Selector function for the property to observe. |
| Action | handler | Delegate to invoke when the property has changed. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of the property. |
Exceptions
| Type | Condition |
|---|---|
| InvalidArgumentException | Thrown if the property selector does not select a valid member on the instance to configure. |
| ArgumentNullException | Thrown if |
Observe<T>(Expression<Func<T>>, Action)
Registers a property with change notification to be observed and handled by the specified delegate.
Declaration
protected void Observe<T>(Expression<Func<T>> propertySelector, Action handler)
Parameters
| Type | Name | Description |
|---|---|---|
| Expression<Func<T>> | propertySelector | Selector function for the property to observe. |
| Action | handler | Delegate to invoke when the property has changed. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of the property. |
Exceptions
| Type | Condition |
|---|---|
| InvalidArgumentException | Thrown if the property selector does not select a valid member on the instance to configure. |
| ArgumentNullException | Thrown if |