ここ
Sorting Data in the Silverlight DataGrid
に書いてある通り、DataGrid#ItemsSourceに渡すオブジェクトとしてIListを実装しているものを渡せばいいらしい。
↓のチュートリアルで表示しているDataGridをソート可能にするには、
Silverlight Tutorial Part 3: Using Networking to Retrieve Data and Populate a DataGrid
↓のように ToList とすればよい。
XDocument xmlStories = XDocument.Parse(xmlContent);
var stories = (from story in xmlStories.Descendants("story")
where story.Element("thumbnail") != null
select new DiggStory()
{
Id = (int)story.Attribute("id"),
Title = (String)story.Element("title"),
Description = (String)story.Element("description"),
ThumbNail = (String)story.Element("thumbnail"),
HrefLink = (String)story.Attribute("link"),
NumDiggs = (int)story.Attribute("diggs")
}).ToList<DiggStory>(); // ← ここ
dgStories.ItemsSource = stories;
DataGrid を使うには、参照 System.Windows.Controls.Data を追加する必要がある。
さらに XAML には、
xmlns:d="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"の記述を追加しておく。
0 件のコメント:
コメントを投稿