We have a WPF Project that follows the MVVM pattern.
In the View Model there is a lot of code that looks like this:
private string m_Fieldname;
public string Fieldname
{
get { return m_Fieldname; }
set
{
m_Fieldname = value;
OnPropertyChanged("Fieldname");
}
}
Is there a way to do this that would require less code?
Would be nice with something like this:
[NotifyWhenChanged]
public string Fieldname { get; set ; }
You could have a look at PostSharp. They even have a sample at Data Binding. The code taken from there:
Usage is then as simple as this:
Examples taken from PostSharp site and inserted for completing the answer