从xml文档跳过元素
问题描述:
我有一个xml文档,我想在其中提取每10个元素。我用这段代码去提取最后10个元素,然后跳过10个元素,然后跳过这10个元素,我使用了这个代码,但是它通过滑动最后10个元素替换了另一个包含最老10的第一个列表,我想要什么在得到最后的10个元素,当用户按下一个按钮,他将得到旧名单摆在他们面前的另一个10个年长元素:从xml文档跳过元素
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);
任何想法,请?
答
不那么远,你只需要创建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):