What's the order of execution when using IDataErrorInfo?
Posted
by Benny Jobigan
on Stack Overflow
See other posts from Stack Overflow
or by Benny Jobigan
Published on 2010-04-16T04:17:24Z
Indexed on
2010/04/16
4:23 UTC
Read the original article
Hit count: 360
Many times with WPF, we use INotifyPropertyChanged
and IDataErrorInfo
to enable binding and validation on our data objects. I've got a lot of properties that look like this:
public SomeObject SomeData
{
get { return _SomeData; }
set { _SomeData = value; OnPropertyChanged("SomeData"); }
}
Of course, I have an appropriate overridden IDataErrorInfo.this[]
in my class to do validation.
Question 1) In a binding situation, what happens?
For example:
- User enters new data.
- Binding writes data to property.
- Property
set
method is executed. - Binding checks
this[]
for validation. - If the data is invalid, the binding sets the property back to the old value.
- Property
set
method is executed again.
This is important if you are adding "hooks" into the set method, like:
public string PathToFile
{
get { return _PathToFile; }
set
{
if (_PathToFile != value && // prevent unnecessary actions
OnPathToFileChanging(value)) // allow subclasses to do something or stop the setter
{
_PathToFile = value;
OnPathToFileChanged(); // allow subclasses to do something afterwards
OnPropertyChanged("PathToFile");
}
}
}
© Stack Overflow or respective owner