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 XAMLI 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.


This content originally appeared on Modern Web Development with Chrome and was authored by Paul Kinlan

<p>I have just been playing with some XAML databinding. I was interested by the <a href="http://channel9.msdn.com/Showpost.aspx?postid=110378">Channel 9 Example</a> which creates an RSS reader in just a couple of lines of XAML<p />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 <a href="http://www.kinlan.co.uk/sample_sources/amazon.xaml">downloaded from my server</a>]:<p /><span class="kwrd"><</span><span class="html">StackPanel</span><span class="attr">xmlns</span><span class="kwrd">="http://schemas.microsoft.com/winfx/avalon/2005"</span> <span class="attr">xmlns:x</span><span class="kwrd">="http://schemas.microsoft.com/winfx/xaml/2005"</span> <span class="attr">Margin</span><span class="kwrd">="10"</span><span class="kwrd">></span> <span class="kwrd"><</span><span class="html">StackPanel.Resources</span><span class="kwrd">></span> <span class="kwrd"><</span><span class="html">XmlDataNamespaceManager</span> <span class="attr">x:Key</span><span class="kwrd">="NS"</span><span class="kwrd">></span> <span class="kwrd"><</span><span class="html">XmlNamespace</span> <span class="attr">Prefix</span><span class="kwrd">="a"</span><span class="attr">Uri</span><span class="kwrd">="http://webservices.amazon.com/ AWSECommerceService /2005-10-05"</span> <span class="kwrd">/></span> <span class="kwrd"></</span><span class="html">XmlDataNamespaceManager</span><span class="kwrd">></span> <span class="kwrd"><</span><span class="html">XmlDataSource</span> <span class="attr">x:Key</span><span class="kwrd">="Amazon"</span> <span class="attr">XmlNamespaceManager</span><span class="kwrd">="{StaticResource NS}"</span><span class="attr">Source</span><span class="kwrd">="http://webservices.amazon.co.uk/onca/xml?Service=AWSECommerceService&</span><span class="kwrd">AssociateTag=cnetfra-21& AWSAccessKeyId=[SUBSCRIPTION ID]& SearchIndex=Books& Keywords=AJAX& BrowseNode=71& ResponseGroup=Request,Large,Images& Sort=salesrank& Operation=ItemSearch"</span><span class="kwrd">/></span><p /> <span class="kwrd"><</span><span class="html">DataTemplate</span> <span class="attr">x:Key</span><span class="kwrd">="TitleTemplate"</span><span class="kwrd">></span> <span class="kwrd"><</span><span class="html">TextBlock</span> <span class="attr">TextContent</span><span class="kwrd">="{Binding XPath=a:ASIN}"</span> <span class="kwrd">/></span> <span class="kwrd"></</span><span class="html">DataTemplate</span><span class="kwrd">></span> <span class="kwrd"></</span><span class="html">StackPanel.Resources</span><span class="kwrd">></span><p /> <span class="kwrd"><</span><span class="html">Label</span> <span class="attr">Content</span><span class="kwrd">="{Binding Source={StaticResource Amazon}, XPath=/a:ItemSearchResponse/a:OperationRequest/ a:HTTPHeaders/a:Header/@Name}"</span> <span class="attr">FontSize</span><span class="kwrd">="24"</span> <span class="attr">FontWeight</span><span class="kwrd">="Bold"</span> <span class="kwrd">/></span> <p /> <span class="kwrd"><</span><span class="html">DockPanel</span> <span class="attr">DataContext</span><span class="kwrd">="{Binding Source={StaticResource Amazon}, XPath=/a:ItemSearchResponse/a:Items/a:Item}"</span> <span class="attr">Height</span><span class="kwrd">="300px"</span> <span class="kwrd">></span> <span class="kwrd"><</span><span class="html">ListBox</span> <span class="attr">DockPanel</span>.<span class="attr">Dock</span><span class="kwrd">="Left"</span> <span class="attr">Binding</span>.<span class="attr">XmlNamespaceManager</span><span class="kwrd">="{StaticResource NS}"</span><span class="attr">ItemsSource</span><span class="kwrd">="{Binding}"</span> <span class="attr">ItemTemplate</span><span class="kwrd">="{StaticResource TitleTemplate}"</span> <span class="attr">IsSynchronizedWithCurrentItem</span><span class="kwrd">="True"</span> <span class="kwrd">/></span> <span class="kwrd"><</span><span class="html">TextBox</span> <span class="attr">Name</span><span class="kwrd">="Contents"</span> <span class="attr">Text</span><span class="kwrd">="{Binding XPath=a:ItemAttributes/a:Title}"</span> <span class="attr">Wrap</span><span class="kwrd">="True"</span> <span class="attr">Width</span><span class="kwrd">="Auto"</span> <span class="kwrd">/></span> <span class="kwrd"></</span><span class="html">DockPanel</span><span class="kwrd">></span><span class="kwrd"></</span><span class="html">StackPanel</span><span class="kwrd">></span><p />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.<p />Now this example I have created leaves a lot to be desired, but you can see how easy it to create.<p /></p>


This content originally appeared on Modern Web Development with Chrome and was authored by Paul Kinlan


Print Share Comment Cite Upload Translate Updates
APA

Paul Kinlan | Sciencx (2005-11-21T00:00:00+00:00) Amazon Search in XAML. Retrieved from https://www.scien.cx/2005/11/21/amazon-search-in-xaml/

MLA
" » Amazon Search in XAML." Paul Kinlan | Sciencx - Monday November 21, 2005, https://www.scien.cx/2005/11/21/amazon-search-in-xaml/
HARVARD
Paul Kinlan | Sciencx Monday November 21, 2005 » Amazon Search in XAML., viewed ,<https://www.scien.cx/2005/11/21/amazon-search-in-xaml/>
VANCOUVER
Paul Kinlan | Sciencx - » Amazon Search in XAML. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2005/11/21/amazon-search-in-xaml/
CHICAGO
" » Amazon Search in XAML." Paul Kinlan | Sciencx - Accessed . https://www.scien.cx/2005/11/21/amazon-search-in-xaml/
IEEE
" » Amazon Search in XAML." Paul Kinlan | Sciencx [Online]. Available: https://www.scien.cx/2005/11/21/amazon-search-in-xaml/. [Accessed: ]
rf:citation
» Amazon Search in XAML | Paul Kinlan | Sciencx | https://www.scien.cx/2005/11/21/amazon-search-in-xaml/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.