With WPF 4.5 we can now bind to static properties. Let's see how.
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.
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
.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 propertyName) { if (StaticPropertyChanged != null) StaticPropertyChanged(null, new PropertyChangedEventArgs(propertyName)); } private static int myAge; public static int MyAge { ...