【问题标题】:skip elements from xml document从 xml 文档中跳过元素
【发布时间】:2012-12-31 11:56:23
【问题描述】:

我有一个 xml 文档,我想在其中提取每 10 个元素。我使用此代码提取最后 10 个元素,然后跳过 10 个元素并获取较旧的元素,我使用了此代码,但它通过跳过最后 10 个元素,将较旧的第一个列表替换为包含最旧 10 个的另一个列表,我想要什么是获取最后 10 个元素,当用户按下按钮时,他将获取较旧的列表和另外 10 个较旧的元素:

slideView.ItemsSource = 
    (from channel in xmlItems.Descendants("album")     
     orderby (int)channel.Element("catid") descending 
     select new onair
     {
         title = (string)channel.Element("name"),
         photo = (string)channel.Element("picture")
     }).Skip(10).Take(10);

有什么想法吗?

【问题讨论】:

    标签: windows-phone-7 linq-to-xml


    【解决方案1】:

    到目前为止,您只需要在 Linq 中创建一些分页(根据您的情况调整此代码)

        public IEnumerable<onair> GetItems(int pageIndex = 0, int pageSize = 10)
        {
            return (from channel in xmlItems.Descendants("album")
                    orderby (int)channel.Element("catid") descending
                    select new onair
                    {
                        title = (string)channel.Element("name"),
                        photo = (string)channel.Element("picture")
                    }).Skip(pageIndex * pageSize).Take(pageSize);
        }
    ...
    
    slideView.ItemsSource = GetItems(2,10):
    

    【讨论】:

      猜你喜欢
      • 2014-06-11
      • 1970-01-01
      • 2015-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-06
      相关资源
      最近更新 更多