For now, I added this method on my model.
public Boolean IsModelValid()
{
Boolean isValid = true;
PropertyInfo[] properties = GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
foreach (PropertyInfo p in properties)
{
if (!p.CanWrite || !p.CanRead)
{
continue;
}
if (this[p.Name] != null)
{
isValid = false;
}
}
return isValid;
}
I bound the object itself on the PropertyChanged event,
public MyClassName()
{
PropertyChanged += CheckModelValidity;
CheckModelValidity(null, null);
}
when it change, I call this method, and if the result is different than my actual public member, I update it:
private void CheckModelValidity(object sender, PropertyChangedEventArgs e)
{
bool isModelValid = IsModelValid();
if(isModelValid!= IsValid)
{
IsValid = isModelValid;
}
}
And then I can just bind the IsValid property.
I don't know if there is a better solution?
this[]
? – Tomsk