From my understanding, we can use the INofityProperty in a MVVM style application with code similar to the following
object _SelectedPerson;
public object SelectedPerson
{
get
{
return _SelectedPerson;
}
set
{
if (_SelectedPerson != value)
{
_SelectedPerson = value;
RaisePropertyChanged("SelectedPerson");
}
}
}
Now, I've seen Josh Smith's excellent example where he implements extra code to capture what happens if the developer types in a Property name which isn't recognized, such as a typo!
Please tell me if you hate this, but there is a way to get the method name from the stack trace. So, we could instead implement something like
object _SelectedPerson;
public object SelectedPerson
{
get
{
return _SelectedPerson;
}
set
{
if (_SelectedPerson != value)
{
_SelectedPerson = value;
RaisePropertyChanged(Current.Method);
}
}
}
static class Current
{
public static string Method()
{
StackTrace st = new StackTrace();
return (st.GetFrame(1).GetMethod().Name.Split('_')[1]);
}
}
I can only assume this will always work since the the RaisePropertyChanged event always occurs in the Setter (and if I'm wrong, please do correct me).
Now please note, I'm not in a position to really try this, in that at work (where I can work on bigger projects) I'm still on .NET 2.0 and so WPF/MVVM is a long way off in the future but I'm learning in my own time.
So, my question is from those who have used it, is it really better to have an approach which alerts the user of the error compared to removing the option for the error (or do you feel I've miss-understood something); the thing is, Josh Smith is recognized, an expert in this field, and so if he suggests that approach then normally I'd follow blindly but in this case I can't help but quiz it and feel the need to understand more.