如何在 Windows Phone 7 中使用联合,如果 IM 按类别对源进行排序

本文关键字:IM 如果 排序 Phone Windows | 更新日期: 2023-09-27 18:30:27

我正在编写一个 Rss 阅读器。我的问题是:如果我使用联合提要,我可以按类别排序吗?这个想法是让源在列表框中显示时已经排序。仅在 1 个预定义类别上排序和显示。

我是一个新的程序员,所以我正在处理这个MSDN示例:http://msdn.microsoft.com/en-us/library/hh487167(v=vs.92).aspx

我正在使用的RSS提要是:http://www.zimo.co/feed/


更新:

我的新尝试解决但失败了:

private void UpdateFeedList(string feedXML)
    {
        StringReader stringReader = new StringReader(feedXML);
        XmlReader xmlReader = XmlReader.Create(stringReader);
                                                              //problem below (I do not get sort method)
        SyndicationFeed feed = SyndicationFeed.Load(xmlReader).Categories.sort();

        Deployment.Current.Dispatcher.BeginInvoke(() =>
        {
           //binding listbox with feed items
            ls_text.ItemsSource = feed.Items;

        });
    }

如何在 Windows Phone 7 中使用联合,如果 IM 按类别对源进行排序

更新我对此进行了更深入的挖掘。首先,仅仅因为每个项目都有多个类别而按类别对项目进行排序对我来说是没有意义的。正如您在下面指出的,您对过滤感兴趣。以下是我是如何做到的(代码进入 UpdateFeedList 事件):

//same code as in the example
SyndicationFeed feed = SyndicationFeed.Load(xmlReader);
//I pull out the distinct list of categories from the entire feed
//You might want to bind this list to a dropdown on your app
//so that users can select what they want to see:
List<string> cats = new List<string>();
foreach (SyndicationItem si in feed.Items)
    foreach(SyndicationCategory sc in si.Categories)
       if (!cats.Contains(sc.Name))
          cats.Add(sc.Name);
//Here I imagined that I want to see all items categorized as "Trendy"
SyndicationCategory lookingFor = new SyndicationCategory("Trendy");
//and I create a container where I could copy all "Trendy" items:
List<SyndicationItem> coll = new List<SyndicationItem>();
//And then I start filtering all items by the selected tag:
foreach (SyndicationItem si in feed.Items)
{
     foreach (SyndicationCategory sc in si.Categories)
         if (sc.Name == lookingFor.Name)
         {
                    coll.Add(si);
                    break;
         }
}
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
    // Bind the filtered of SyndicationItems to our ListBox.
       feedListBox.ItemsSource = coll;
       loadFeedButton.Content = "Refresh Feed";
});

以下任何不正确的内容

yoursyndicationfeed.Categories.Sort()

我个人不会按除日期降序之外的任何内容对 RSS 提要进行排序(它应该已经排序了),因为 RSS 提要以与发布相反的顺序为我提供了网站内容的更新,并且我习惯于大多数人看到它:)

另一个更新(:)也不正确)

好的,所以我面前仍然没有该应用程序的代码,但是深入研究文档(我在评论中提到),您可以执行以下操作:

SyndicationFeed feed = SyndicationFeed.Load(xmlReader); 
feed.Items.OrderBy(x => x.Category);

这个想法是饲料。项目是元素的列表。因此,将其视为列表,按所需的属性对其进行排序。

哦,还有,我在RSS阅读器上看到了您的另一个问题,您必须使用该示例吗?Scott Guthrie为Windows Phone 7编写了一个RSS客户端,他的实现似乎更简单一些。当然,这取决于您的需求。