Binding Enhancements in WPF 4.5
Though it isn’t in the spotlight any more, WPF still continues to be a key-stone for rich client development on Windows. With full access to the .NET libraries and the underlying operating system, no other HTML or .NET-based UI technology can match it. Recognizing its importance, Microsoft is continuing to invest in improving WPF and especially its binding capabilities.
First up is support for binding to static properties via the class name. The syntax is slightly different than normal binding. Pete Brown explains,
Note the modification to the binding syntax. You'll use parentheses around the namespace, class, and property because, as Sam Bent explained to me "They tell us to parse the path as ClassName.PropertyName rather than PropertyName.PropertyName."
Since binding to properties often requires change notifications, WPF 4.5 offers two design patterns. The first is to create a one-off event with the signature “public static event EventHandler [PropertyName]Changed”. If there are several properties that need to be watched, a general purpose event can be used instead. This uses the signature “public static event EventHandler<PropertyChangedEventArgs> StaticPropertyChanged”.
Another feature coming to WPF 4.5 is delay binding. Normally data changes are immediately pushed from the control to the model. When a delay is set the updated value isn’t pushed until the user stops making changes for indicated time span. Pete offers a couple of examples including:
Another useful place for this is when binding to data in a TextBox where you want to catch incremental changes, but the cost (for example, a search) is somewhat expensive. In that case, you can wait for a slight pause, maybe 100ms between keystrokes, and perform your search then.
Ian Culling, Andy Powell & Lee Cunningham Dec 11, 2013