Amazon Search in XAML

I have just been playing with some XAML databinding. I was interested by the Channel 9 Example which creates an RSS reader in just a couple of lines of XAML

I hooked it up to Amazons REST API. I had a couple of problems with it that I will go into later. But what follows is the XAML that I used [also it can be downloaded from my server]:


<StackPanel
xmlns="http://schemas.microsoft.com/winfx/avalon/2005" xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005" Margin="10">
<StackPanel.Resources>
<XmlDataNamespaceManager x:Key="NS">
<XmlNamespace Prefix="a"
Uri
="http://webservices.amazon.com/ AWSECommerceService /2005-10-05" />
</XmlDataNamespaceManager>
<XmlDataSource x:Key="Amazon" XmlNamespaceManager="{StaticResource NS}"
Source="http://webservices.amazon.co.uk/onca/xml?Service=AWSECommerceService&
AssociateTag=cnetfra-21& AWSAccessKeyId=[SUBSCRIPTION ID]&
SearchIndex=Books& Keywords=AJAX& BrowseNode=71& ResponseGroup=Request,Large,Images& Sort=salesrank& Operation=ItemSearch"
/>

<DataTemplate x:Key="TitleTemplate">
<TextBlock TextContent="{Binding XPath=a:ASIN}" />
</DataTemplate>
</StackPanel.Resources>

<Label Content="{Binding Source={StaticResource Amazon}, XPath=/a:ItemSearchResponse/a:OperationRequest/ a:HTTPHeaders/a:Header/@Name}" FontSize="24" FontWeight="Bold" />

<DockPanel DataContext="{Binding Source={StaticResource Amazon},
XPath=/a:ItemSearchResponse/a:Items/a:Item}"
Height="300px" >
<ListBox DockPanel.Dock="Left" Binding.XmlNamespaceManager="{StaticResource NS}"
ItemsSource="{Binding}" ItemTemplate="{StaticResource TitleTemplate}" IsSynchronizedWithCurrentItem="True" />
<TextBox Name="Contents" Text="{Binding XPath=a:ItemAttributes/a:Title}" Wrap="True" Width="Auto" />
</DockPanel>
</StackPanel>

The major problem that I had was that the AMAZON API has a default namespace, therefore to be able to use XPath against the datasource you need to include a NamespaceManager so that the XPath queries are resolved correctly. Once this is done everything is really simple.

Now this example I have created leaves a lot to be desired, but you can see how easy it to create.

Technorati Tags
[feed], [feed], [feed], [feed], [feed], [feed], [feed], [feed], [feed], [feed], [feed], [feed]

Related Wikipedia Documents
, , , , , , , , , , , , ,

My Related Documents
, , , ,

Related Amazon Books
Programming Windows Presentation Foundation: /, Service-Oriented Architecture: Concepts, Technology, and Design: /, Service-oriented Architecture: A Field Guide to Integrating XML and Web Services: /, Mining Amazon Web Services: Building Applications with the Amazon API: /, Professional Web APIs with PHP: Google, EBay, Paypal, Amazon, Yahoo, Fedex: /, Amazon Hacks: /, MCAD Training Guide 70-320: Developing XML Web Services and Server Components with Visual C#.NET and the .NET Framework: /, Expert Service-Oriented Architecture in C#: Using the Web Services Enhancements 2.0: /, RSS and Atom Hacks: /, RSS and Atom: Understanding and Implementing Content Feeds and Syndication: /

Related Images From Flickr
[[posterous-content:vEnxaHvuhblybsgmcIaw]][[posterous-content:FHGmxpqucaCjfxoqdktg]][[posterous-content:FxafxgtBghxxoouJtrll]][[posterous-content:cvEkgDceklqFwzpxJomn]][[posterous-content:whwhmIdHhiJHjHyraxEp]][[posterous-content:askzfEjDkrbwlkryfcDr]][[posterous-content:amtjFAACvpHJBadwHGiE]]