RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Flexible and Powerful Data Binding with WPF

Microsoft has been building data binding frameworks for years, and each promises to solve our data binding woes forever. But we're still waiting for the perfect one. Could WPF data binding be the one we've been waiting for?

hough ata binding is pervasive in Windows Presentation Foundation (WPF), it's also different enough that you'll need to rethink the way you use it in your applications. .NET 3.5 SP1, released in August 2008, is more than just a bug-and-performance fix service pack. It is a feature release service pack—meaning that in addition to the bug fixes, it also contains many new features. Upgrading to SP1 makes sense for WPF applications because the upgrade adds a significant number of essential updates. On the other hand, Microsoft did not release SP1 as a version release, e.g. 3.6, which complicates your deployment story.

The upgrade of WPF is full of surprises for seasoned .NET developers. It delivers a new UI composition model, a brand new XAML markup language, and the perplexing dependency property system. There is so much to learn, the question is: Where do you start? One good starting point is Wei-Meng Lee's "An Overview of Windows Presentation Foundation" article (CoDe Magazine, Mar/Apr 2006). I have my own short list of favorite concepts to learn in WPF. Here are two.

  • First, learn about templates and their close cousins, styles. They are an astoundingly good way to design and render a user interface.
  • Second, invest some time in understanding the new data binding model. It's time well spent.
Binding Frameworks
Data binding has been around in some form for years. Both Windows Forms and ASP.NET have binding implementations available. The motivation behind creating a binding framework is that it reduces the amount of code that the application developer must write. You rely on the teams at Microsoft to produce the mountains of code necessary to simplify your daily coding tasks.

WPF is a complete rethinking of how to construct a UI development platform. Since Microsoft started with a blank slate, it provided the WPF architects with the opportunity to engineer interesting ideas into the binding engine.
The central idea behind binding is simple. You "bind" some UI controls to a data object and then rely on the binding framework to push the data to the controls and ensure that changed data is saved back to the business object properties.

I'd define WPF data binding as the ability to register two items, a data source and a data target, with the binding framework. That's as far as the developer's responsibility goes. The binding framework is responsible for synchronizing the data between the two registered items and providing other services, such as validation and data conversion.

But that simple explanation hardly reveals the power of WPF binding. WPF is a complete rethinking of how to construct a UI development platform. Because Microsoft started with a blank slate, the WPF architects had the opportunity to engineer interesting ideas into their binding engine. Binding in WPF is pervasive and built into every corner of the system. It permits better abstraction of code and UI by allowing complete separation of UI design from business object code. Data templates are another unique idea within WPF. If you're coming from a Windows Forms or ASP.NET background, you'll find templates force you to change the way you think about developing and designing user interfaces.

Editor's Note: This article was first published in the November/December 2008 issue of CoDe Magazine, and is reprinted here by permission.

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date