BT

Binding Enhancements in WPF 4.5

by Jonathan Allen on Dec 08, 2011 |

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.

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2014 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT