Sample of MVVM Light working with NotifyPropertyWeaver

Jan 12, 2011 at 12:08 AM

For those who are interested I have included an MVVM Light sample in the latest release of http://code.google.com/p/notifypropertyweaver/

So now you can write this

public class PersonViewModel : ViewModelBase
{
public string GivenNames { get; set; }
public string FamilyName { get; set; }

public string FullName
{
get
{
return string.Format("{0} {1}", GivenNames, FamilyName);
}
}
}

And this will get compiled

public class PersonViewModel : ViewModelBase
{

private string givenNames;
public string GivenNames
{
get { return givenNames; }
set
{
if (value != givenNames)
{
givenNames = value;
RaisePropertyChanged("GivenNames");
RaisePropertyChanged("FullName");
}
}
}

private string familyName;
public string FamilyName
{
get { return familyName; }
set
{
if (value != familyName)
{
familyName = value;
RaisePropertyChanged("FamilyName");
RaisePropertyChanged("FullName");
}
}
}

public string FullName
{
get
{
return string.Format("{0} {1}", GivenNames, FamilyName);
}
}
}

The sample is here in source control
http://code.google.com/p/notifypropertyweaver/source/browse/#svn%2Ftrunk%2FSamples%2FMvvmLightWpfSample

The setup instructions are here
http://code.google.com/p/notifypropertyweaver/wiki/Setup
With the only difference being (for MVVM Light) to change the EventInvokerName

<NotifyPropertyWeaverMsBuildTask.WeavingTask TargetPath="$(TargetPath)" TryToWeaveAllTypes="true" EventInvokerName="RaisePropertyChanged" />

Hope this is of use to some people.