[英]limit number of listbox items to be displayed on load, programmatically
我有一個 Silverlight 2.0 列表框,它從自定義列表中讀取數據@ SharePoint 2007。如何限制在加載 Page.Z44CC44B81911F4BA4581C725DA61 時顯示的項目數量?
在這里我有@ Page.xaml.cs:
private void ProcessResponse()
{
XDocument results = XDocument.Parse(_responseString);
_StaffNews = (from item in results.Descendants(XName.Get("row", "#RowsetSchema"))
//where !item.Element("NewsThumbnail").Attribute("src").Value.EndsWith(".gif")
select new StaffNews()
{
Title = item.Attribute("ows_Title").Value,
NewsBody = item.Attribute("ows_NewsBody").Value,
NewsThumbnail = FormatImageUrl(item.Attribute("ows_NewsThumbnail").Value),
DatePublished = item.Attribute("ows_Date_Published").Value,
PublishedBy = item.Attribute("ows_PublishedBy").Value,
}).ToList();
this.DataContext = _StaffNews;
//NewsList.SelectedIndex = -1;
}
您可以將.Take(20)
放在ToList()
) 后面,以僅從列表中獲取 20 個項目。
Take方法允許您對項目設置限制。 它只會迭代集合,直到達到最大計數。 您可以只使用它而不是ToList()
或者如果_StaffNews
被定義為List<T>
,只需將它們組合起來.Take(items).ToList();
private void ProcessResponse()
{
var items = 10;
XDocument results = XDocument.Parse(_responseString);
_StaffNews = (from item in results.Descendants(XName.Get("row", "#RowsetSchema"))
//where !item.Element("NewsThumbnail").Attribute("src").Value.EndsWith(".gif")
select new StaffNews()
{
Title = item.Attribute("ows_Title").Value,
NewsBody = item.Attribute("ows_NewsBody").Value,
NewsThumbnail = FormatImageUrl(item.Attribute("ows_NewsThumbnail").Value),
DatePublished = item.Attribute("ows_Date_Published").Value,
PublishedBy = item.Attribute("ows_PublishedBy").Value,
}).Take(items);
this.DataContext = _StaffNews;
//NewsList.SelectedIndex = -1;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.