Are there any recommendations about performing asynchronous MVVM-ish validations in WPF? Have read about INotifyDataErrorInfo, but unfortunately is only available to Silverlight.
Thanks.
IDataErrorInfo is the data validation mechanism for WPF. Don't you just love Microsoft's consistency? ;)
Implement IDataErrorInfo on your ViewModel like this:
public class MyViewModel : IDataErrorInfo
{
public string Error
{
get {
return GetErrorStringForThisViewModelInGeneral();
}
}
public string this[string columnName]
{
get
{
string result = null;
switch (columnName)
{
case "Quantity":
if (Quantity <= 0)
result = "Quantity must be greater than 1.";
break;
}
return result;
}
}
Inside of the property (aka this[]) validation, you could use the validator in the EnterpriseLibrary, a custom validator using Attributes, or anything you like. I am just showing a basic implementation to get you started.