ControlValidation class Core

Binds a control's Control.Error to what a model says about one of its properties, through INotifyDataErrorInfo or IDataErrorInfo (read by DataErrors, the same reading a grid's edit policy uses). The message follows the model: a view model that validates on every change marks the field red while it is wrong and clears it when it is right, with no code in the form.

public static class ControlValidation
Namespace
ArionUI.Presentation.Controls
Package
ArionUI.Presentation · dotnet add package ArionUI.Presentation --prerelease

Methods

BindErrors

public static IDisposable BindErrors(this Control control, object model, string property);

Shows the errors of property of model on control from now on. The model's events may come from any thread: the message is set on the UI thread - posted through the host of the control's tree (its dispatcher, else its next frame), or, for a control not in a tree yet, to the synchronization context the binding was made on. The binding holds the control weakly - a model that outlives its form does not keep the form alive - and ends by itself once the control is gone. Dispose the result to end it sooner; no message is set after that.