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]:

<StackPanelxmlns="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.

I lead the Chrome Developer Relations team at Google.

We want people to have the best experience possible on the web without having to install a native app or produce content in a walled garden.

Our team tries to make it easier for developers to build on the web by supporting every Chrome release, creating great content to support developers on web.dev, contributing to MDN, helping to improve browser compatibility, and some of the best developer tools like Lighthouse, Workbox, Squoosh to name just a few.

I love to learn about what you are building, and how I can help with Chrome or Web development in general, so if you want to chat with me directly, please feel free to book a consultation.

I'm trialing a newsletter, you can subscribe below (thank you!)