Show / Hide Table of Contents

Class ViewModelBase

Base class for creating ViewModels.

Inheritance
object
NotifyPropertyChangeBase
NotifyPropertyChanged
ViewModelBase
EntityViewModel<T>
FormViewModelBase
WindowViewModel
Implements
INotifyPropertyChangeBase
IRefreshable
INotifyPropertyChanged
Inherited Members
NotifyPropertyChanged.PropertyChanged
NotifyPropertyChanged.Notify(params string[])
NotifyPropertyChanged.Notify(string)
NotifyPropertyChanged.RaisePropertyChangeEvent(in string, in PropertyChangeNotificationType)
NotifyPropertyChanged.OnDoChange<T>(ref T, T, string)
NotifyPropertyChangeBase.OnInitialize(NotifyPropertyChangeBase.IPropertyBroadcastSetup)
NotifyPropertyChangeBase.Refresh()
NotifyPropertyChangeBase.Subscribe(PropertyInfo, PropertyChangeObserver)
NotifyPropertyChangeBase.Subscribe(PropertyChangeObserver)
NotifyPropertyChangeBase.Subscribe(Expression<Func<object>>, PropertyChangeObserver)
NotifyPropertyChangeBase.Unsubscribe(PropertyChangeObserver)
NotifyPropertyChangeBase.Unsubscribe(PropertyInfo)
NotifyPropertyChangeBase.Unsubscribe(Expression<Func<object>>)
NotifyPropertyChangeBase.Change<T>(ref T, T, string)
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: TheXDS.MCART.Types.Base
Assembly: MCART.Mvvm.dll
Syntax
public abstract class ViewModelBase : NotifyPropertyChanged, INotifyPropertyChangeBase, IRefreshable, INotifyPropertyChanged

Constructors

| Edit this page View Source

ViewModelBase()

Initializes a new instance of the ViewModelBase class.

Declaration
protected ViewModelBase()

Properties

| Edit this page View Source

IsBusy

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 Source

BusyOp(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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

~ViewModelBase()

Finalizes this instance of the ViewModelBase class.

Declaration
protected ~ViewModelBase()
| Edit this page View Source

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 propertySelectors or handler is null.

EmptyCollectionException

Thrown if propertySelectors contains no elements.

| Edit this page View Source

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 propertyName is an empty or whitespace string.

ArgumentNullException

Thrown if propertyName or handler is null.

| Edit this page View Source

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 propertyNames is null, an empty string, or whitespace.

ArgumentNullException

Thrown if propertyNames or handler is null.

| Edit this page View Source

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 source, property, or handler is null.

| Edit this page View Source

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 source, propertySelector, or handler is null.

| Edit this page View Source

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 propertySelector or handler is null.

Implements

INotifyPropertyChangeBase
IRefreshable
INotifyPropertyChanged

Extension Methods

Objects.ShallowCopyTo(object, object, Type)
ObjectExtensions.FieldsOf<T>(object)
ObjectExtensions.GetAttribute<T>(object)
ObjectExtensions.GetAttributes<T>(object)
ObjectExtensions.HasAttrValue<TAttribute, TValue>(object, out TValue)
ObjectExtensions.HasAttribute<T>(object)
ObjectExtensions.HasAttribute<T>(object, out T?)
ObjectExtensions.HasAttributes<T>(object, out IEnumerable<T>?)
ObjectExtensions.Is(object?, object?)
ObjectExtensions.IsEither(object, IEnumerable)
ObjectExtensions.IsEither(object, params object[])
ObjectExtensions.IsNeither(object, IEnumerable)
ObjectExtensions.IsNeither(object, params object[])
ObjectExtensions.IsNot(object?, object?)
ObjectExtensions.PropertiesOf<T>(object)
ObjectExtensions.WhichAre(object, IEnumerable<object>)
ObjectExtensions.WhichAre(object, params object[])
Common.IfNotNull<T>(T?, Action<T>)
Objects.Itself<T>(T)
Objects.ShallowCopyTo<T>(T, T)
ObservingCommandBuilder.Create<T>(T, Action)
ObservingCommandBuilder.Create<T>(T, Action<object?>)
ObservingCommandBuilder.Create<T>(T, Func<object?, Task>)
ObservingCommandBuilder.Create<T>(T, Func<Task>)
ObservingCommandBuilder.Create<T, TParam>(T, Action<TParam>)
ObservingCommandBuilder.Create<T, TParam>(T, Func<TParam, Task>)
CollectionExtensions.PushInto<TItem, TCollection>(TItem, ICollection<TCollection>)
DictionaryExtensions.PushInto<TKey, TValue>(TValue, TKey, IDictionary<TKey, TValue>)
NotifyPropertyChangeBaseExtensions.Subscribe<T>(T, Expression<Func<T, object?>>, PropertyChangeObserver)
NotifyPropertyChangeBaseExtensions.Unsubscribe<T>(T, Expression<Func<T, object?>>)
  • Edit this page
  • View Source
In this article
Back to top Generated by DocFX