Table of Contents

Class ModelBase

Namespace
EasySoftware.MvvmMini
Assembly
EasySoftware.MvvmMini.dll

Base class for bindable models with built-in validation error storage. Implements INotifyPropertyChanged, INotifyDataErrorInfo and IErrorContainer.

public abstract class ModelBase : BindableBase, IModel, INotifyPropertyChanged, INotifyDataErrorInfo, IErrorContainer
Inheritance
ModelBase
Implements
Derived
Inherited Members

Remarks

Object-level errors are stored under the Empty key.

Constructors

ModelBase()

Initializes a new instance of the ModelBase class with no errors.

public ModelBase()

Properties

Errors

Gets or sets all errors, keyed by property name.

public IReadOnlyDictionary<string, IEnumerable<string>> Errors { get; set; }

Property Value

IReadOnlyDictionary<string, IEnumerable<string>>

Remarks

Object-level errors use the Empty key. Setting this property replaces the current errors with a copy of the given ones.

HasErrors

Gets a value indicating whether the container holds at least one error.

public virtual bool HasErrors { get; }

Property Value

bool

Methods

AddError(string)

Adds an object-level error that is not tied to a specific property.

public void AddError(string errorMessage)

Parameters

errorMessage string

The error message to add.

Exceptions

ArgumentNullException

errorMessage is null or empty.

AddError(string, string)

Adds an error for the specified property and raises ErrorsChanged. A message that the property already has is not added twice.

public void AddError(string propName, string errorMessage)

Parameters

propName string

The property name, or null or empty for an object-level error.

errorMessage string

The error message to add.

Exceptions

ArgumentNullException

errorMessage is null or empty.

ClearErrors()

Removes all errors and raises ErrorsChanged for each property that had errors.

public void ClearErrors()

ClearErrors(string)

Removes all errors of the specified property and raises ErrorsChanged if it had any.

public void ClearErrors(string propName)

Parameters

propName string

The property name, or null or empty for object-level errors.

CloneErrors(IErrorContainer)

Replaces the current errors with a copy of the errors of another container.

public virtual void CloneErrors(IErrorContainer other)

Parameters

other IErrorContainer

The container to copy the errors from.

GetErrors(string)

Gets the errors of the specified property, or the object-level errors when propertyName is null or empty.

public virtual IEnumerable GetErrors(string propertyName)

Parameters

propertyName string

The property name, or null or empty for object-level errors.

Returns

IEnumerable

The errors of the property, or null if it has none.

RaiseErrorsChanged(string)

Raises ErrorsChanged for the specified property.

public void RaiseErrorsChanged(string propName)

Parameters

propName string

The property name, or Empty for object-level errors.

Events

ErrorsChanged

Occurs when the validation errors have changed for a property or for the entire entity.

public event EventHandler<DataErrorsChangedEventArgs> ErrorsChanged

Event Type

EventHandler<DataErrorsChangedEventArgs>