Sunday, October 03, 2010 11:40 PM Tanzim Saqib

Creating a News Framework Windows Phone 7 App

UPDATE: for Oct 25, 2010 changes. Full source code is available.

News Framework is a tiny library (DLL) that you can use to build your own Windows Phone 7 application in just minutes especially if you have a news portal and your site exposes RSS data. If you are not sure about News Framework yet, see introductory video here. I have built a fully functioning unofficial Mashable app using this framework which you will find in News Framework codeplex site. You can use that as a template while you build your own.

Step 1: Get the tools

One of the good reasons why everyone can now have his/her own WP7 is that the tools it requires are all free. Download and install the tools from there and News Framework from here: http://newsfx.codeplex.com/ and follow the steps. You will find the simplest form of template application built for you in src\TanzimSaqib.NewsFramework.Demo using News Framework. You can change the namespace, backgrounds and what not to tailor to your needs.

Step 2: Tailor to your needs

Take a look at the app.config file now:

<?xml version="1.0" encoding="utf-8" ?>
<appSettings>
<add name="AppTitle" value="Mashable! Social Media News and Web Tips – The Social Media Guide" />
<add name="AppHomepage" value="http://www.mashable.com" />
<add name="ShareArticleSubjectTemplate" value="Check it out" />
<add name="ShareArticleBodyTemplate" value="Hi, check out this cool article: &quot;{article-title}&quot;. URL: {article-url}" />
<add name="DarkThemeBackground" value="/DarkThemeBackground.png" />
<add name="LightThemeBackground" value="/LightThemeBackground.png" />
<add name="PageOrientation" value="Both" /> <!-- Portrait OR Landscape -->
<add name="FeedsPath" value="/Feeds.xml" />
<add name="RssItemCount" value="10" />
<add name="ClearCacheOnStartUp" value="false" />
<add name="Article-View-CSS" value="body { font-size: 14px; }" />
<add name="Article-View-DarkBackground-CSS" value="body { background-color: black; color: white; } a { background-color: white; color: black; }" />
<add name="Article-View-LightBackground-CSS" value="body { background-color: transparent; color: black; }" />
</appSettings>


As you can see, these are the options that you can control from outside of the framework (i.e. your application). The properties are quite self-explanatory and I believe they don’t require to be described in great detail. Many more new settings yet to be added. Now let’s take a look at a piece of code that is mandatory according to the XML format of the RSS that your site exposes. In the constructor of the App (App.xaml.cs) class of your WP7 application, you need to specify how it will find the thumbnail and content tags from the Feed XML.
Fx.Initialize(this, new RssExtendedParser()
{
ThumbnailParser = (item) =>
{
Check.Null(item);

return item.Element(item.GetNamespaceOfPrefix("mash") + "thumbnail")
.Element("img")
.Attribute("src")
.Value;
},

ContentParser = (item) =>
{
Check.Null(item);

return item.Element(item.GetNamespaceOfPrefix("content") + "encoded")
.Value;
}
});


You will have to create an instance of RssExtendedParser which has two properties. Pass two delegates to them to direct how a single RSS item (node) will be handled with respect to the thumbnail and content extraction. We need this because almost all popular news sites expose thumbnails and content with their own namespace. For Mashable it was mash:thumbnail and mash:content. For example:

<mash:thumbnail>
<img src="http://cdn.mashable.com/wp-content/uploads/2010/11/foodwine_ipad_thumb.jpg"
alt="Food &amp; Wine Magazine Serves Up Holiday Treats for the iPad"
class="post_image item" />
</mash:thumbnail>

<content:encoded><![CDATA[<p><div><div
style="float:right;margin-bottom:10px;"><a
target="_blank" href="...">
...
</content:encoded>

 

Now that the application is ready. It is time to feed the RSS. Open up Data\Feeds.xml and enter URLs to the feeds like the following:

<?xml version="1.0" encoding="utf-8" ?>
<feeds main="http://feeds.mashable.com/Mashable">
<feed title="Social Media Channel"
url="http://feeds.mashable.com/mashable/socialmedia"
subtitle="The latest happenings in social media, plus tips on using Twitter, Facebook, YouTube, Foursquare and more." />

<feed title="Tech Channel"
url="http://feeds.mashable.com/mashable/tech"
subtitle="Gadgets, software, web design, web development, video games and geek culture."/>

<feed title="Business Channel"
url="http://feeds.mashable.com/mashable/business"
subtitle="Small business, advertising and marketing, money and finance, plus careers and business apps."/>

...

...

</feeds>


main attribute of the feeds tag is the feed URL that is being used to render feed items in the main screen as latest, and the feed tags inside feeds are the ones for rendering categories and their respective feed items. Hope this helps you get started with writing your own Windows Phone 7 app using News Framework.

Comments

# Twitter Trackbacks for 3 steps to build a Windows Phone 7 app using News Framework - Tanzim Saqib - Microsoft MVP, ASP.NET [asp.net] on Topsy.com

Pingback from  Twitter Trackbacks for                 3 steps to build a Windows Phone 7 app using News Framework - Tanzim Saqib - Microsoft MVP, ASP.NET         [asp.net]        on Topsy.com

# re: 3 steps to build a Windows Phone 7 app using News Framework

Monday, October 04, 2010 1:48 PM by Jacob Gable

I've tried this with two different RSS Feeds and neither of them work. (Try jacob4u2.blogspot.com/.../default) Unless you release the source for the referenced .DLL, TanzimSaqib.NewsFramework, you really can't get much use out of this framework.  

That referenced DLL looks more like another win phone 7 app than a class library when put through reflector, which is a little sketchy (sketchy == it looks suspicious).

It's a good idea, but it needs some polishing and testing with other feeds.

# re: 3 steps to build a Windows Phone 7 app using News Framework

Monday, October 04, 2010 9:56 PM by Tanzim Saqib

it hasn't become v1 yet. So, fixing and polishing efforts are going on. Thanks Jacob for your feedback though.

# re: 3 steps to build a Windows Phone 7 app using News Framework

Tuesday, October 05, 2010 12:07 PM by Tim

Why am I getting this error when I run the project to test it?

Not sure If I need to modify something at first or what steps I need to take.

--------------

Error 1 Cannot create an instance of "MainPagePanorama". C:\Users\tim\Desktop\NewsFx_demo\demo1\Mashable\MainPage.xaml 18 9 Mashable

-------------------------

Thanks!

tim

# re: 3 steps to build a Windows Phone 7 app using News Framework

Tuesday, October 05, 2010 12:12 PM by Tanzim Saqib

Should run as is.

1. Have you referenced to TanzimSaqib.NewsFramework.dll?

2. Also, have you written the namespace in MainPage.xaml file?

ie. xmlns:NewsFramework="clr-namespace:TanzimSaqib.NewsFramework;assembly=TanzimSaqib.NewsFramework"

# re: 3 steps to build a Windows Phone 7 app using News Framework

Tuesday, October 05, 2010 2:49 PM by Tim

Thanks for the quick reply!

I checked option 1 and 2 that you listed and everything was there on default from the file I downloaded at codeplex but still shows that error (Cannot create an instance of "MainPagePanorama")

On MainPage.xaml these two lines are underlined:

a) d:DataContext="{d:DesignData SampleData/MainViewModelSampleData.xaml}"

b)  <Grid x:Name="LayoutRoot" Background="Transparent">

       <NewsFramework:MainPagePanorama />

   </Grid>

# re: 3 steps to build a Windows Phone 7 app using News Framework

Thursday, October 07, 2010 9:49 AM by Cheekit

Not able to open the file::

1. d:DataContext="{d:DesignData SampleData/MainViewModelSampleData.xaml}"

such that         <NewsFramework:MainPagePanorama />

becomes NullReference..

# re: 3 steps to build a Windows Phone 7 app using News Framework

Thursday, October 07, 2010 11:29 PM by Tanzim Saqib

@Cheekit, design-time data is unnecessary. Having said that NewsFramework doesn't have good design-time support at this release.

# RSS News Framework for Windows Phone 7 &laquo; Vincent Leung .NET Tech Clips

Pingback from  RSS News Framework for Windows Phone 7 &laquo; Vincent Leung .NET Tech Clips

# re: 3 steps to build a Windows Phone 7 app using News Framework

Friday, November 19, 2010 4:06 PM by sri

hi Tanzim, do you have plans to release the code as well on the codeplex. I would love to use it and also add some enhancements to over its current form

# re: Creating a News Framework Windows Phone 7 App

Friday, November 19, 2010 10:00 PM by Tanzim Saqib

sri, it's already there. For your convenience I have updated this blog post. Please feel free to share your ideas.

# re: Creating a News Framework Windows Phone 7 App

Wednesday, December 22, 2010 4:35 AM by Ragnar

I dont know which values I have to give to GetNamespaceOfPrefix. This is my RSS-Feed but I dont have insight into its XML

blogs.msdn.com/.../rss.aspx

# re: Creating a News Framework Windows Phone 7 App

Wednesday, December 29, 2010 6:37 AM by Dimis

Hi Tanzim!

Thanks a lot for your help giving us the opportunity to share our ideas! I saw your project and I attempted to run it. I took the next error:

Error 1 Cannot create an instance of "MainPagePanorama". C:\Users\admin\Desktop\NewsFx_demo\demo1\Mashable\MainPage.xaml 19 9 Mashable

Also I took the next warning:

Warning 2 The file 'SampleData/MainViewModelSampleData.xaml' is not part of the project or its 'Build Action' property is not set to 'Resource'. C:\Users\admin\Desktop\NewsFx_demo\demo1\Mashable\MainPage.xaml 11 20 Mashable.

Can you help me?

Thanks in advance.

# re: Creating a News Framework Windows Phone 7 App

Thursday, December 30, 2010 12:04 AM by Tanzim Saqib

Hi All, please list your issues here, and will be picked up:

newsfx.codeplex.com/.../basic

# Offline RSS Reading Framework for Windows Phone | I Love Windows Phone!

Pingback from  Offline RSS Reading Framework for Windows Phone  |  I Love Windows Phone!

# 50+ Windows Phone App Ideas | Tanzim Saqib

Wednesday, February 15, 2012 3:03 AM by 50+ Windows Phone App Ideas | Tanzim Saqib

Pingback from  50+ Windows Phone App Ideas | Tanzim Saqib

# 50+ Windows Phone App Ideas | Tanzim Saqib&#039;s notes

Sunday, July 08, 2012 4:42 AM by 50+ Windows Phone App Ideas | Tanzim Saqib's notes

Pingback from  50+ Windows Phone App Ideas | Tanzim Saqib&#039;s notes

Leave a Comment

(required) 
(required) 
(optional)
(required)