Tuesday, June 10, 2008

Technorati claim

Technorati Profile

Introduction to Data Binding in WPF

Recently an article was published on CodeProject about Data Binding in WPF.
The article is Titled Moving Toward WPF Data Binding One Step at a Time
It is accompanied by a sample projcet that illustrates how a tightly coupled WPF application can be transformed into a loosely coupled WPF application.

Core of project is in XAML file for Window object supported by the Code-Behind file.

In First version, XAML simply declares controls while all binding of data to control happens in code.
Code depends on control names defined in XAML, meaning any change in XAML will have to be matched inside code.
Also, necessary code needs to be explicitly written to accept user input and update underlying data source.

In Second version, Code makes use of Binding object in System.Windows.Data namespace.
Binding object enables binding of a UI control to data source through properties Source and Path.
Source property of Binding object refers to data source object while Path property refers to individual member belonging to data source object.
Once these properties are set, no explicit code is needed to update data to\from control.

In Third and Fourth version, data binding is done from within XAML.
Difference between two versions is only in usage of Binding Markup Extension.
One version uses Property Element syntax while other uses Attribute syntax.
Final version turns out to be A very compact XAML with minimal code.
In both versions, code-behind is reduced to a single statement that simply sets the data context.

At the core of this transformation is the "Binding" object\markup extension.
It allows to accomplish declarative Data Binding from within XAML while data remains de-coupled from UI controls.
UI can be designed to look entirely different using entirely different set of controls while bare minimum changes are needed to supporting data objects.

References :
CodeProject portal has several other excellent articles on WPF
Wealth of information on WPF on MSDN
WPF Forums on MSDN

Monday, June 9, 2008

Welcome

Welcome to my blog