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


Create Data-Aware Applications in "Avalon"—the Windows Presentation Foundation : Page 2

In WPF you can bind UI elements to a wide variety of data sources, including XML data, Web services, as well as databases. Learn how data-binding works in the Windows Presentation Foundation with this sample project using an XML data source.

Binding to an External XML Source
The previous example shows how you can bind an XML data island to the various controls in your WPF application. One problem with using an XML data island within the application is that any changes to the XML data will require the application to be modified/compiled. A better approach would be to store the XML data in an external file and then reference it within the application. For example, you could save the XML data in a file called RSS.xml and then reference it within the application as:

         <XmlDataSource x:Key="RSSData" 
Dynamically Loading the XML Source
While you can reference an external XML file, a better approach would be to dynamically load the XML document from a URL. In this case, you would modify your <XmlDataSource> element as:

        <XmlDataSource x:Key="RSSData" 
Try using the following URLs and see that the application loads a different set of RSS items each time: Going Further
In this article, you have seen how data-binding works in WPF. For those who want to take the sample application further, consider modifying the application to allow users to select from a list of URLs (instead of manually modifying the source of the XML document). Otherwise, I encourage you to download the sample code and see for yourself how data binding works in WPF.

Wei-Meng Lee is a Microsoft MVP and founder of Developer Learning Solutions, a technology company specializing in hands-on training on the latest Microsoft technologies. He is an established developer and trainer specializing in .NET and wireless technologies. Wei-Meng speaks regularly at international conferences and has authored and coauthored numerous books on .NET, XML, and wireless technologies. He writes extensively on topics ranging from .NET to Mac OS X. He is also the author of the .NET Compact Framework Pocket Guide, ASP.NET 2.0: A Developer's Notebook (both from O'Reilly Media, Inc.), and Programming Sudoku (Apress). Here is Wei-Meng's blog.
Email AuthorEmail Author
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date