Windows phone 8 绑定到listbox时从listbox中删除第一项

Windows phone 8 绑定到listbox时从listbox中删除第一项,windows-phone-8,Windows Phone 8,我已经解析了提要 rss源中的所有项目都显示在列表框中。现在我不想得到第一个项目,我必须忽略它。我该怎么做呢 MainPage.xaml.cs: 如果我写queue.removet0; 我在RemoveAt时出错了。 谁能告诉我怎么做。 非常感谢。您可以使用LINQ Skip扩展方法文档轻松完成此操作。 请尝试以下示例: itemsList.ItemsSource = queue.Skip(1); var document = XDocument.Parse(e.Result); var in

我已经解析了提要 rss源中的所有项目都显示在列表框中。现在我不想得到第一个项目,我必须忽略它。我该怎么做呢

MainPage.xaml.cs:

如果我写queue.removet0; 我在RemoveAt时出错了。 谁能告诉我怎么做。
非常感谢。

您可以使用LINQ Skip扩展方法文档轻松完成此操作。 请尝试以下示例:

itemsList.ItemsSource = queue.Skip(1);
var document = XDocument.Parse(e.Result);
var indexes = new HashSet<int> { 1, 3, 4 }; 

var queue = document.Descendants("item")
    .Select(item => new Item
    {
        title = item.Element("title").Value,
        link = item.Element("link").Value,
        ThumbnailUrl =
            item.Element(item.GetNamespaceOfPrefix("media") + "thumbnail").Attribute("url").Value,
    })
    .Where((x, i) => !indexes.Contains(i))
    .ToList();

Items.ItemsSource = queue;
此外,在使用“方法链”方法在选择方法中应用投影之前,可以重写查询以省略第一项:

var queue = document.Descendants("item")
            .Skip(1)
            .Select(item => new Item
                    {
                        title = item.Element("title").Value,
                        link = item.Element("link").Value,
                        ThumbnailUrl = item.Element(item.GetNamespaceOfPrefix("media") + "thumbnail").Attribute("url").Value,
                    })
            .ToList();

itemsList.ItemsSource = queue;
更新/由于评论

此外,如果您需要跳过某些索引中的项目,您可以使用Where方法和HasSet,如下示例所示:

itemsList.ItemsSource = queue.Skip(1);
var document = XDocument.Parse(e.Result);
var indexes = new HashSet<int> { 1, 3, 4 }; 

var queue = document.Descendants("item")
    .Select(item => new Item
    {
        title = item.Element("title").Value,
        link = item.Element("link").Value,
        ThumbnailUrl =
            item.Element(item.GetNamespaceOfPrefix("media") + "thumbnail").Attribute("url").Value,
    })
    .Where((x, i) => !indexes.Contains(i))
    .ToList();

Items.ItemsSource = queue;

非常感谢。如果我们只需要显示第一个项目,而忽略其余的项目,我们可以跳过多个项目吗。许多问题如果我需要随机跳过两个或三个项目,我该怎么办positions@deepu如果您使用任何类型的标准来检测这些项目?抱歉,我不明白。我的意思是,如果我需要显示所选项目,我可以使用计数,像这样跳过第二个元素。XmlSerializer serializer=新的XmlSerializertypeofChannel;XDocument document=XDocument.Parsee.Result;Channel=Channelserializer.Deserializedocument.CreateReader;//如果channel.Collection.Count>0 channel.Collection.RemoveAt0,则删除第一项;this.myListBox.ItemsSource=channel.Collection;ManyThanks@deepu现在,我不太确定,如果我不理解你,我想你需要跳过某些索引处的元素,对吗?如果是这样,我建议使用Where方法。例如,假设您需要跳过索引为1、3和4的项,以下代码将起作用:var index=newhashset{1、3、4};this.myListBox.ItemsSource.Collection=channel.Collection.Wherex,i=>!index.contains假设channel.Collection属性实现IEnumerable