Page view counter
QuickStart Description
Animations Describes how to create basic animations by changing property values and by using key frames.
Audio and Video Describes how to integrate media into your applications.
Images Describes how to integrate images into your applications.
Deep Zoom Describes how to create a Deep Zoom image, load a Deep Zoom image, and add interactivity.
Control Templates Describes how to create a ControlTemplate to customize the appearance of a CheckBox control.
Data Binding to Controls Describes how to data bind to a control and customize the display.
HTML Bridge Describes how to access the HTML DOM from managed code, and to call managed code from JavaScript.
Isolated Storage Describes how to save and retrieve data as key-value pairs or files in isolated storage.
LINQ to XML Describes hows how to use LINQ to filter, group, sort, transform, and project an RSS feed.
Syndication Feeds Describes how to create a Silverlight client that can access and display a syndication service.
Web Services Provides an introduction to using Web services in Silverlight.
Dynamic Languages Demonstrates dynamic languages (Python and Ruby) by showing the DLR Console sample.
Home > Quickstarts > Syndication Feeds

Syndication Feeds

This QuickStart describes how to create a Silverlight client that can access and display a syndication service that exposes either an RSS 2.0 or Atom 1.0 syndication feed.

This QuickStart contains the following sections:

Note

Syndication in Silverlight is based largely on the Windows Communication Foundation (WCF) object model. For an in-depth description of the WCF syndication feature set, see WCF Syndication in the MSDN Library.


Accessing a Syndication Feed with a Silverlight Client

Syndication items can be accessed in Silverlight by using a System.Net.WebClient object to asynchronously download and read strings using a System.Xml.XmlReader from a feed. The following example accesses a syndication feed that provides the top stories at Wired magazine. To try this example, click Click Here for the Feed. A list of feed items appears below the button.

The following managed code in the Page.xaml (Page.xaml.cs or Page.xaml.vb) file shows how you access the syndication items from the feed. Uri identifies the address of the feed to be accessed. It points to the Wired magazine syndication feed.

C#

using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using System.ServiceModel.Syndication; using System.Xml; using System.IO; namespace SyndicationFeedReader { public partial class Page : UserControl { public Page() { InitializeComponent(); } void OnClick(object sender, EventArgs args) { WebClient client = new WebClient(); client.DownloadStringAsync( new Uri("http://feeds.wired.com/wired/index?format=xml")); client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(request_DownloadStringCompleted); } void request_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { XmlReader reader = XmlReader.Create(new StringReader(e.Result)); SyndicationFeed feed = SyndicationFeed.Load(reader); lbSyndicationItems.ItemsSource = feed.Items; } } }

Visual Basic

Imports System Imports System.Collections.Generic Imports System.Linq Imports System.Net Imports System.Windows Imports System.Windows.Controls Imports System.Windows.Documents Imports System.Windows.Input Imports System.Windows.Media Imports System.Windows.Media.Animation Imports System.Windows.Shapes Imports System.ServiceModel.Syndication Imports System.Xml Imports System.IO Namespace SyndicationFeedReader Public Partial Class Page Inherits UserControl Public Sub New() InitializeComponent() End Sub Private Sub OnClick(sender As Object, args As EventArgs) Dim client As New WebClient() client.DownloadStringAsync( New Uri("http://feeds.wired.com/wired/index?format=xml")) client.DownloadStringCompleted += New DownloadStringCompletedEventHandler(request_DownloadStringCompleted) End Sub Private Sub request_DownloadStringCompleted(sender As Object, e As DownloadStringCompletedEventArgs) Dim reader As XmlReader = XmlReader.Create(New StringReader(e.Result)) Dim feed As SyndicationFeed = SyndicationFeed.Load(reader) lbSyndicationItems.ItemsSource = feed.Items End Sub End Class End Namespace
 

Displaying a Syndication Feed

Feed tiles can be displayed by binding the titles of the feed topics to the Text property of the TextBlock.

XAML

<UserControl x:Class="SyndicationFeedReader.Page" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="600" Height="500"> <Grid x:Name="LayoutRoot" Background="Blue"> <Grid.RowDefinitions> <RowDefinition Height="100"/> <RowDefinition /> </Grid.RowDefinitions> <Button Grid.Row="0" Margin=" 5" Height="60" Content="Click Here for the Feed" Click="OnClick"/> <ListBox x:Name="lbSyndicationItems" Margin="4" Grid.Row="1"> <ListBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Title.Text}"/> </DataTemplate> </ListBox.ItemTemplate>> </ListBox> </Grid> </UserControl>

The following code shows how to bind the data from the SyndicationFeed object.

C#

lbSyndicationItems.ItemsSource = feed.Items;

Visual Basic

lbSyndicationItems.ItemsSource = feed.Items

Cross-Domain Calls

It is important to note that the call to the Wired site is a cross-domain call. It works here because the Wired feed has a cross-domain file that enables it. The cross-domain file can be accessed at Wired cross-domain file. Other feeds will have to be similarly enabled for cross-domain calls if they are to be accessed in this way. For more information, see Making a Service Available Across Domain Boundaries in the Silverlight documentation on MSDN.


See Also


Send Feedback
Microsoft Communities