|
using WpfFormsWithValidationDemo.Toolkit.ViewModel;
namespace WpfFormsWithValidationDemo.ViewModel
{
public abstract class FormViewModelBase : ValidationViewModelBase
{
private bool isValid;
private readonly string formName;
/// <summary>
/// Gets a value indicating whether the form is valid in its current state. If all properties
/// wich validation are valid, this property returns true.
/// </summary>
public bool IsValid
{
get
{
return this.isValid;
}
protected set
{
this.isValid = value;
this.OnPropertyChanged("IsValid");
}
}
/// <summary>
/// Gets the name of the form.
/// </summary>
public string FormName
{
get
{
return this.formName;
}
}
protected FormViewModelBase(string formName)
{
this.formName = formName;
this.PropertyChangedCompleted(string.Empty);
}
protected override void PropertyChangedCompleted(string propertyName)
{
// test prevent infinite loop while settings IsValid
// (which causes an PropertyChanged to be raised)
if (propertyName != "IsValid")
{
// update the isValid status
if (string.IsNullOrEmpty(this.Error) && this.ValidPropertiesCount == this.TotalPropertiesWithValidationCount)
{
this.IsValid = true;
}
else
{
this.IsValid = false;
}
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.