Class FormViewModelBase
Base class for view models that provide form services and data validation.
Inherited Members
Namespace: TheXDS.MCART.Types.Base
Assembly: MCART.Mvvm.dll
Syntax
public abstract class FormViewModelBase : ViewModelBase, INotifyPropertyChangeBase, IRefreshable, INotifyPropertyChanged, INotifyDataErrorInfo
Properties
| Edit this page View SourceErrorSource
Returns this instance; required for proper INotifyPropertyChanged implementation.
Declaration
public INotifyDataErrorInfo ErrorSource { get; }
Property Value
| Type | Description |
|---|---|
| INotifyDataErrorInfo |
HasErrors
Gets a value indicating whether this instance has any validation errors.
Declaration
public bool HasErrors { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Methods
| Edit this page View SourceCheckErrors()
Runs all validations and returns whether they all passed.
Declaration
public bool CheckErrors()
Returns
| Type | Description |
|---|---|
| bool | true if all validations passed and there is at least one rule; otherwise, false. |
GetErrors(string?)
Enumerates the errors for the provided property name, or for all
properties if propertyName is
null or empty.
Declaration
public IEnumerable GetErrors(string? propertyName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | propertyName | Name of the property for which to get the errors. If it is an empty string or null, this method returns all validation errors. |
Returns
| Type | Description |
|---|---|
| IEnumerable | An enumeration of all validation error messages for the specified property or for all properties. |
OnDoChange<T>(ref T, T, string)
Overrides Change<T>(ref T, T, string) to run validations for a property when its value changes.
Declaration
protected override void OnDoChange<T>(ref T backingStore, T value, string propertyName)
Parameters
| Type | Name | Description |
|---|---|---|
| T | backingStore | Field that holds the property value. |
| T | value | Value to set. |
| string | propertyName | Name of the property. This parameter should normally be omitted (compiler-inferred) unless a different property must be notified. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of the backing field. |
Overrides
| Edit this page View SourceRegisterValidation<T>(Expression<Func<T>>)
Registers a validation ruleset for a property.
Declaration
protected FormViewModelBase.IValidationEntry<T> RegisterValidation<T>(Expression<Func<T>> propertySelector)
Parameters
| Type | Name | Description |
|---|---|---|
| Expression<Func<T>> | propertySelector | Expression that selects the property to configure. |
Returns
| Type | Description |
|---|---|
| FormViewModelBase.IValidationEntry<T> | An object that allows configuring the validation rules to apply to the selected property. |
Type Parameters
| Name | Description |
|---|---|
| T | Property type. |
ValidationAffects(params SimpleCommand[])
Informs the validation engine which commands are affected by validation failures.
Declaration
protected void ValidationAffects(params SimpleCommand[] commands)
Parameters
| Type | Name | Description |
|---|---|---|
| SimpleCommand[] | commands | Commands that should be disabled when validation fails. |
Remarks
Call this method after instantiating the commands.
Events
| Edit this page View SourceErrorsChanged
Triggered whenever validations are run.
Declaration
public event EventHandler<DataErrorsChangedEventArgs>? ErrorsChanged
Event Type
| Type | Description |
|---|---|
| EventHandler<DataErrorsChangedEventArgs> |