Data binding to static properties

With WPF 4.5 we can now bind to static properties. Let's see how.

Getting ready

In order to use this recipe you should have Visual Studio 2012 installed.

How to do it...

In this recipe, we are going to see how to use the capability of WPF in .NET 4.5 to bind to static properties as well as how to define and notify their property changes.

  1. First, open Visual Studio 2012 and create a new project. We will select the WPF Application template from the Visual C# category and name it WPFStaticPropertiesBinding.
  2. Add a class and name it MyStaticDetails.cs, adding the following code:
    public class MyStaticDetails { public static event EventHandler<PropertyChangedEventArgs> StaticPropertyChanged; protected static void OnPropertyChanged(string ...

Get Microsoft .NET Framework 4.5 Quickstart Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.