Windows Phone : Simple RSS Application

Introduction

There is nothing new in RSS feeds. For the past decade, there have been very many RSS Applications developed in all platforms. Even so, we will show you a simple RSS application that works on Windows Phone Applications.

image1.gif

Background

We will use a simple XML Parser with some LINQ commands. In the XAML portion, we will bind the target with the XML source.

Procedure

Step 1: First, we will define our XAML portion. So, add a ListBox for where we will bind our data.

Inside the main grid, add the ListBox definition.

image2.gif

Now, we will define the three Text Blocks, one for Title, another for Date of Publish and the last one for Description.

image3.gif

Here, we have bound the values to the Title, Date and Description that we will define soon in the back-end CS file.

Step 2: Next, we define the back-end CS file.

First add a class file (RSSItem.cs) to the project.

Note: Right-click on your project in Solution Explorer then select "Add" > "Class" and name it as you want, for now name it RSSItem.cs.

There, define the following property within the new class:

image4.gif
You must take care that, whatever name you have used while binding should be same.

For example, Title is the same as {Binding path=Title}.

Step 3: After this, we want data to be fetched from the XML file when the application loads itself.

So, the best idea is to program the Constructor.

Before doing this, add "using System.Xml.Linq;" in your project.

(Before that, right-click on "Reference" then select "Add Reference" > "Select System.Xml.Linq".)

Create an object of a web client, since we will use it soon in the XML Parser.

image5.gif

After that, create an event that gets raised when the form loads.

image6.gif

So, when DownloadStringCompleted is raised the Client_DownloadStringCompleted handler is called.

In that method, we write

image7.gif
Here, we have fetched data from the title, pubDate and description nodes and assigned them to respective data members (variables).

In the last line, we linked the source (RSSdata) to the Target, in other words our List in XAML window (myList).

Ultimately, we got our output as:

image8.gif

Conclusion

We can use this for any website that supports XML RSS feeds. Since it will not work for a feed burner (word press) so, avoid it for those. It will work for sure on any exact XML file (like rss.xml).

Apart from that, you can add a click event to navigate to their actual link so that the user can read the news or feed from a website.

Up Next
    Ebook Download
    View all
    Learn
    View all