将Rss内容读取到Listbox control中, 然后实现按照标题或发布日期进行排序。
private void ListItemSort(string type) { if (type == "title") { var list = ItemBox.Items.Cast<SyndicationItem>().OrderBy(item => item.Title.Text).ToList(); if (ItemBox.ItemsSource != null) ItemBox.ItemsSource = null; ItemBox.Items.Clear(); foreach (SyndicationItem item in list) { ItemBox.Items.Add(item); } } else if (type == "date") { var list = ItemBox.Items.Cast<SyndicationItem>().OrderBy(item => item.PublishDate.LocalDateTime).ToList(); if (ItemBox.ItemsSource != null) ItemBox.ItemsSource = null; ItemBox.Items.Clear(); foreach (SyndicationItem item in list) { ItemBox.Items.Add(item); } } }
需要这两个类库:
using System.ServiceModel.Syndication; using System.Collections;