Access Yahoo! Web Services Using XAML

XAML is Microsoft's declarative markup language for creating applications, UIs and even documents. The most common place to use XAML is in conjunction with the Windows Presentation Foundation and it makes it possible to create user interfaces that use data binding wholly in an XML-based markup


When working with XAML we can use the XmlDataProvider object to retrieve XML data and provide it to controls.

The following samples can be pasted directly into XamlPad.

Using XAML to Create a Weather Badge

The following sample demonstrates using an XmlDataProvider to retrieve data from a web service, retrieve specific data fields from multiple namespaces using XPath and creates a FlowDocument with the returned data.

XAML Weather Badge

First, we create a XmlDataProvider that will retrieve data asyncronously from the given address and create the data collection with XPath from /rss/channel. The second step is to use data from the data provider and this is done using binding extensions in XAML. Since we have multiple namespaces the actual XPath statements that retrieve the data may look a little confusing at first, but all we are really doing is checking the namespace to get the nodes from the correct one. Most of the code comes from defining the document structure we are displaying and getting access to the nested properties, mainly TextBlock.Text.Binding.XPath.

XAML Weather Badge Sample

Binding XML to a ListBox

The following sample retrieves data and displays the result in a ListBox grouped by <author>.

XAML Databound ListBox Sample

Further reading

Related information on the web is listed below.

Yahoo Forum Discussions