(1) Създаваме нов проект в Microsoft Visual Studio 2012, със следния избор за проекта: Visual C# > Windows Store > Grid App > OK.

(2) Отваряме: Solution Explorer > DataModel > SampleDataSource.cs

(3) Добавяме в него следните пространства с имена:
using Windows.Web.Syndication; using System.Threading.Tasks; using System.Text.RegularExpressions; using System.IO;

(4) Заместваме кода на класа: public sealed class SampleDataSource
public sealed class SampleDataSource
{
public static ObservableCollection<SampleDataGroup> _allGroups = new ObservableCollection<SampleDataGroup>();
public static ObservableCollection<SampleDataGroup> AllGroups { get { return _allGroups; }}
public static SampleDataGroup GetGroup(string uniqueId){
var matches = AllGroups.Where((group) => group.UniqueId.Equals(uniqueId));
if (matches.Count() == 1) return matches.First();
return null;
}
public static SampleDataItem GetItem(string uniqueId) {
var matches = AllGroups.SelectMany(group =>
group.Items).Where((item) => item.UniqueId.Equals(uniqueId));
if (matches.Count() == 1) return matches.First();
return null;
}
public static async Task<bool> AddGroupForFeedAsync(string feedUrl) {
if (SampleDataSource.GetGroup(feedUrl) != null) return false;
var feedClient = new SyndicationClient();
var feed = await feedClient.RetrieveFeedAsync(new Uri(feedUrl));
var feedGroup = new SampleDataGroup( uniqueId: feedUrl, title: feed.Title != null ? feed.Title.Text : null, subtitle: feed.Subtitle != null ? feed.Subtitle.Text : null, imagePath: feed.ImageUri != null ? feed.ImageUri.ToString() : null,  description: null);
foreach (var i in feed.Items) {
string imgPath = GetImageFromPostContents(i);
if (imgPath != null && feedGroup.Image == null)  feedGroup.SetImage(imgPath);
var dataItem = new SampleDataItem( uniqueId: i.Id, title: i.Title.Text,  subtitle: null, imagePath: imgPath, description: null,  content: i.Summary.Text,  @group: feedGroup);
feedGroup.Items.Add(dataItem);
}
AllGroups.Add(feedGroup);
return true;
}
private static string GetImageFromPostContents(SyndicationItem item) {
var regex = new Regex( "[src href]\\s*=\\s*(?:\"(?<1>[^\"]*)\"|(?<1>\\S+))");
var matches = regex.Matches(item.Summary.Text);
return matches.Cast<Match>()
.Where(m => { Uri url;
if (Uri.TryCreate(m.Groups[1].Value, UriKind.Absolute, out url)) {
string ext = Path.GetExtension(url.AbsolutePath).ToLower();
if (ext == ".png" || ext == ".jpg" || ext == ".jpeg") return true;
}
return false;
}).Select(m => m.Groups[1].Value).FirstOrDefault();
}
}

(5) Отваряме: Solution Explorer > GroupedItemsPage.xaml > GroupedItemsPage.xaml.cs

(6) В метода: protected async override void LoadState, записваме следното:
this.DefaultViewModel["Groups"] = SampleDataSource.AllGroups;
await SampleDataSource.AddGroupForFeedAsync("http://www.sportal.bg/uploads/rss_category_0.xml");

Автор: Димитър Минчев

Доктор по информатика и компютърни науки