Windows Template Studio — Simplify Properties with Fody

Scott Kuhl
2 min readJul 23, 2019

--

In this short article, I add Fody to make properties a little simpler.

Properties with Fody.

What is Fody?

Specifically I am talking about the PropertyChanged.Fody NuGet package. This handy little package does one simple thing: it helps standard properties implement the PropertyChanged event.

So something this …

private SampleOrder _item;

public SampleOrder Item
{
get { return _item; }
set { Set(ref _item, value); }
}

Can be written like this …

public SampleOrder Item { get; set; }

And it still notifies data bound XAML that a change has occurred!

Adding Fody to the Code Behind Design Pattern

  1. Add the Fody NuGet package to the app project.
  2. Add the PropertyChanged.Fody NuGet package to the app project.
  3. Remove the Set and OnPropertyChanged methods from your code behind on your pages. Do not remove the PropertyChanged event.
  4. Update properties on the pages that were using the old method to simple properties with getters and setters.

Adding Fody to the MVVM Basic Design Pattern

  1. Add the Fody NuGet package to the app project.
  2. Add the PropertyChanged.Fody NuGet package to the app project.
  3. Update any class that is using the Observable Set method to use a simple getter and setter.

You can leave the Set method in place in case you need to add a more complex update scenario like throwing an event when a property is updated.

The other three MVVM frameworks available in Windows Template Studio are also listed as supported by Fody, these follow essential the same steps.

That’s it!

--

--