Skip to content

ValidatingBindable

Niclas Kristek edited this page Aug 21, 2019 · 1 revision

The ValidatingBindable abstract class provides an implementation of the INotifyDataErrorInfo interface and inherits from Bindable.

SetErrors

To set the errors of a property use the SetErrors method. It's important to set the errors every time validation is performed. When no errors exist, set an empty enumeration or null.

private object _myProperty;

public object MyProperty
{
    get => _myProperty;
    set
    {
        if (SetProperty(ref _myProperty, value)
        {
            // perform validation like
            var errors = new List<string>();
            if (MyProperty == null)
                errors.Add("MyProperty should not be null.");
            SetErrors(errors);
        }
    }
}
Clone this wiki locally