(1) RSS实体类和RSS服务类
RssItem.cs using System.Net; using System.Text.RegularExpressions; namespace WindowsPhone.Helpers { ///
/// 内容
/// 发表事件
/// 文章地址
public RssItem(string title, string summary, string publishedDate, string url) { Title = title; Summary = summary; PublishedDate = publishedDate; Url = url; //解析html PlainSummary = HttpUtility.HtmlDecode(Regex.Replace(summary, "<[^>]+?>", "")); } //标题 public string Title { get; set; } //内容 public string Summary { get; set; } //发表时间 public string PublishedDate { get; set; } //文章地址 public string Url { get; set; } //解析的文本内容 public string PlainSummary { get; set; } } }
RssService.cs
using System; using System.Collections.Generic; using System.IO; using System.Net; using System.ServiceModel.Syndication; using System.Xml; namespace WindowsPhone.Helpers { ///
/// 获取完成事件
public static void GetRssItems(string rssFeed, Action
(2) RSS页面展示
MainPage.xaml
MainPage.xaml.cs
using System.Windows; using System.Windows.Controls; using Microsoft.Phone.Controls; using WindowsPhone.Helpers; namespace ReadRssItemsSample { public partial class MainPage : PhoneApplicationPage { private string WindowsPhoneBlogPosts = ""; public MainPage() { InitializeComponent(); } private void Button_Click(object sender, RoutedEventArgs e) { if (rssURL.Text != "") { WindowsPhoneBlogPosts = rssURL.Text; } else { MessageBox.Show("请输入RSS地址!"); return; } //加载RSS列表 RssService.GetRssItems( WindowsPhoneBlogPosts, (items) => { listbox.ItemsSource = items; }, (exception) => { MessageBox.Show(exception.Message); }, null ); } //查看文章的详细内容 private void _disibledevent=>object sender, SelectionChangedEventArgs e) { if (listbox.SelectedItem == null) return; var template = (RssItem)listbox.SelectedItem; MessageBox.Show(template.PlainSummary); listbox.SelectedItem = null; } } }
(3)程序运行的效果如下
最新评论