Build an RSS Reader for Windows Phone 7
Join the DZone community and get the full member experience.
Join For FreeIn this lesson, I will create a simple RSS(Really Simple Syndication) Reader for Windows Phone 7. I will use Linq-To-XML for reading an RSS feed. The user interface will contain a Textbox to enter an URL of an RSS Feed and a ListBox element to display results.
Source code
Additional information
1. Creating a new project
First of all, you need to create a new project. To do so open Visual Studio 2010 -> File -> New Project -> select Windows Phone Application there as it is shown in the picture below.
eugenedotnet creating windows phone 7 project
2. Adding a new reference to solution
Next, you need to add a reference to Microsoft.Xml.Linq library. You need to right-click on the References directory under your project and select Add Reference there. Under the .NET tab, you will find Microsoft.Xml.Linq, push OK. Check the screenshot below.
eugenedotnet add Microsoft.Xml.Linq reference
3. Modifying header
This step can be optional, but I have decided to add it to the lesson. In this step, we simply modify the TitleGrid element to specify the title of the application.
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="24,24,0,12"> <TextBlock x:Name="ApplicationTitle" Text="EUGENEDOTNET.COM" Margin="0,0,0,0" Style="{StaticResource PhoneTextNormalStyle}"/> <TextBlock x:Name="PageTitle" Text="RSS Reader" Margin="-3,-8,0,0" Style="{StaticResource PhoneTextTitle1Style}"/> </StackPanel> |
4. Modifying ContentGrid
ContentGrid will contain all the required UI elements to operate with our application. Basically, there will be three of them:
- TextBox for user to enter an URL of a RSS Feed
- Button to trigger an event to read feed
- ListBox to display results using the Data Binding feature of Silverlight (e.g {Binding Title} ). ListBox will display a title and a link to each of the results.
NB! Pay attention that click event is added to a button in XAML. Also, notice the new InputScope feature of Windows Phone 7 is applied to TextBox making it easier for users to enter URLs into the Textbox element by providing a URL-specific virtual keyboard (SIP) layout by default.
<Grid x:Name="ContentGrid" Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="70" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBox Name="tbRSSFeedURL" Grid.Row="0" Text="" Width="350" Margin="10,0,10,0" HorizontalAlignment="Left">
<TextBox.InputScope>
<InputScope>
<InputScopeName NameValue="Url" />
</InputScope>
</TextBox.InputScope>
</TextBox>
<Button Name="btnReadFeed" Grid.Row="0" Content="Read" Width="110" Margin="10,0,10,0" HorizontalAlignment="Right" Click="btnReadFeed_Click" />
<ScrollViewer Width="440" Height="530" Grid.Row="1" Margin="10, 20, 0, 0">
<ListBox Name="listboxRSSFeedItems" Width="440" Height="530">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock TextWrapping="Wrap" Text="{Binding Title}" Grid.Row="0" FontSize="24" HorizontalAlignment="Left" />
<HyperlinkButton Content="Link to details" NavigateUri="{Binding Link}" HorizontalAlignment="Left" Grid.Row="1" Margin="0,0,0,30" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</ScrollViewer>
</Grid>
5. Creating a class for a single RSS Feed item
Now we simply need to create a new container-class for holding RSS Feed data.
public class RSSFeedItem { public string Title { get; set; } public Uri URL { get; set; } }
6. Implementing event functionality
Next, we need to write a code for processing the “Read” button click event. It should create a new URI object and pass it to the ReadRss method to begin reading an RSS Feed.
private void btnReadFeed_Click(object sender, RoutedEventArgs e) { if (!string.IsNullOrEmpty(tbRSSFeedURL.Text)) { ReadRss(new Uri(tbRSSFeedURL.Text, UriKind.Absolute)); } }
7. Implementing application logic
First of all make sure that MainPage.xaml class (codebehind) is using the following references.
using System.Xml.Linq; // for reading RSS using Linq-To-XML using System.IO; // for Stream object
Next, you need to implement a ReadRss method that takes URI (URL) as an input parameter. If the request is successful then the application will process the results of reading an RSS feed (but only 10 first according to. Take(10) line in code) and add them using ForEach to a listbox. ListBox will display results according to the Data Binding specified above.
public void ReadRss(Uri rssUri) { WebClient wclient = new WebClient(); wclient.OpenReadCompleted += (sender, e) => { if (e.Error != null) return; Stream str = e.Result; XDocument xdoc = XDocument.Load(str); // take 10 first results List<RSSFeedItem> rssFeedItems = (from item in xdoc.Descendants("item") select new RSSFeedItem() { Title = item.Element("title").Value, URL = new Uri(item.Element("link").Value, UriKind.Absolute), }).Take(10).ToList(); // close str.Close(); // add results to listbox listboxRSSFeedItems.Items.Clear(); rssFeedItems.ForEach(item => listboxRSSFeedItems.Items.Add(item)); }; wclient.OpenReadAsync(rssUri); }
The Origins of Windows Phone 7
Windows Phone 7 is the first iteration of a mobile client operating system that Microsoft released for worldwide distribution in October 2010.
Over the years, there have been various iterations of Microsoft’s mobile operating system, culminating in Windows 10 Mobile.
However, the operating system and Microsoft mobile phones never really took off and, despite features like the RSS feed functionality described above, January 2020 saw the end of life with the final cumulative update issued officially by Microsoft.
Windows 10 Build 15251.603 was rolled out to the Lumia 950 and HP Elite x3 without much fanfare and lacking a detailed changelog. Clearly, the company was cutting its losses and moving on.
For those with the Windows Mobile 10 OS, the final update included some security fixes as well as a few general improvements. None of which was much to write home about.
Indications are that the security bugs that were fixed are related to the Windows Kernel, Input, and Composition as well as a few additional components.
For those who were unlucky enough to own the Windows Phone, Microsoft confirmed in 2020 that they would no longer support the phone. If it’s still working, you can still use the phone, but apps such as WhatsApp may no longer function.
Device Backups
But all was not lost as you could still backup your device. Your settings and data were safe until March 2020, at which time Microsoft abandoned their customers and scrapped the ability to access backups too.
They back-pedaled a bit by informing everyone that the photo uploads and a few other features would still be available for a further 12 months and that it really was a good idea to make other arrangements to retrieve and store any valuable or sentimental data, voice, and image files.
Support for Office Apps
It's not unexpected that Microsoft didn’t treat Office Mobile apps for Windows 10 as an urgent priority.
The support for Office apps ended in January 2021 with a trickle of security updates coming through during the course of 2021.
Microsoft’s Advice - Switch to Android or iOS
For those customers still looking for alternatives, Samsung and Apple were obvious alternatives. These Android and iOS-supported devices were on Microsoft’s list of mobile platforms to receive updated apps.
The expectation is that the customers who were let down in the past were likely to continue to support the company that failed them in the past. Time will tell whether this is the case or not.
For those users who are still interested in RSS feeds, there are various options in both the Google Play Store and the Apple store.
Although RSS feeds have largely been replaced by followers joining mailing lists of their favorite brand or blogger, there are still a few diehard holdouts who are comfortable receiving an aggregated service via RSS feeds.
Opinions expressed by DZone contributors are their own.
Comments