Chapter 5: Data Binding


Overview

Data binding in its traditional sense means associating some underlying data with one or more user interface elements. The data provides the information to display. The user interface elements render the information in the appropriate format.

Longhorn extends the traditional idea of data binding in a number of ways. You can bind a property of a user interface element to a property of any common language runtime (CLR) object, or to an attribute of an XML node.

The data binding can be unidirectional (in either direction) or bidirectional. For example, traditional data binding has the information in the data source flow to its bound user interface element. Alternatively, the information in the user interface element can flow back to the data source. Bidirectional data binding, of course, supports information flow in each direction and enables user input via user interface element to update the data in the data source.

Data binding can also be static (one time only) or dynamic. With static data binding, the information transfer occurs when you initially create the data binding. Subsequent changes to values in the data do not affect the value in the user interface element. Dynamic data binding allows changes to data in the data source to propagate to the User Interface element and vice versa.

Longhorn data binding also supports transformation of the data as it flows to and from the data source and user interface elements. This transformation enables the application author to add UI semantics to the data.

Some typical transformations might be the following:

  • Displaying negative numbers in red and positive numbers in black

  • Displaying images based on a contact being online or offline

  • Creating dynamic bar charts by binding a rectangle s height to a stock price

  • Animating the position of an image by binding its coordinates to a property of a CLR object

Longhorn data binding is also fundamentally asynchronous. A user interface element receives an event when a new data source binds to the element. In addition, as a data source collects its data, it fires events to indicate that its contents have changed.

One can data-bind to any CLR object or XMLnode, and hence one can easily data-bind to various data models in Longhorn ”CLR objects, XML, ADO.NET Datasets, Web service messages, or WinFS objects. Longhorn also provides a number of built-in data source classes that allow you to easily and declaratively bring data asynchronously into an application. There are specific data sources for XML, .NET objects, ADO.NET datasets, and WinFS objects. The data source model is extensible, so you can create your own custom data source classes when necessary.




Introducing Microsoft WinFX
Introducing WinFX(TM) The Application Programming Interface for the Next Generation of Microsoft Windows Code Name Longhorn (Pro Developer)
ISBN: 0735620857
EAN: 2147483647
Year: 2004
Pages: 83
Authors: Brent Rector

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net