Windows Phone 7 : Building Simple RSS Reader

Here we will build simple RSS reader in Windows Phone. Reading RSS is reading XML file online. So you need some engineering between XML and XAML. Here you go.

Your phone UI

 <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
    <ListBox Name="lstRSS">
                    <TextBlock Text="{Binding Path=Title}"></TextBlock>
                    <TextBlock Text="{Binding Path=PubDate}"></TextBlock>
                    <TextBlock Text=" "></TextBlock>

Then the class to define the structure

 public class RSSClass
    public string Title { get; set; }
    public string PubDate { get; set; }

After that we need few lines to read it online.

 public Page1()

    WebClient myRSS = new WebClient();
    myRSS.DownloadStringCompleted += new DownloadStringCompletedEventHandler(myRSS_DownloadStringCompleted);

    //Read Async
    myRSS.DownloadStringAsync(new Uri(@""));

void myRSS_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
    //Check if the Network is available
    if (!Microsoft.Phone.Net.NetworkInformation.DeviceNetworkInformation.IsNetworkAvailable)
        var rssData = from rss in XElement.Parse(e.Result).Descendants("item")
                        select new RSSClass
                            Title = rss.Element("title").Value,
                            PubDate = rss.Element("pubDate").Value
        lstRSS.ItemsSource = rssData;
        MessageBox.Show("No network is available..");