welcome to Qijie's Blog 薛其杰

将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;

 

posted on 2013-07-17 17:26  零点零一  阅读(652)  评论(0编辑  收藏  举报