如果我有未排序的集合,是否有一種簡單的方法來綁定和排序它。我想這樣做在XAML(沒有LINQ的,不C#)如何綁定和排序集合
如果我的DataContext有一個屬性,比如說,MyItems,很容易綁定反對:
<ListBox ItemsSource={Binding MyItems}/>
不過,我會喜歡分類。使用CollectionViewSource應該是解決方案,但它並沒有爲我工作:
<ListBox>
<ListBox.ItemsSource>
<Binding>
<Binding.Source>
<CollectionViewSource Source={Binding MyItems}/>
</Binding.Source>
</Binding>
</ListBox.ItemsSource>
</ListBox>
在這一點上,我的列表框失去它的元素。 我錯過了一些明顯的東西嗎?
謝謝你的建議。但是,我的列表框位於DataTemplate中,因此我無法使用資源。它爲什麼作爲資源而不是作爲綁定的來源? – user380719 2011-04-07 18:27:46
啊你原來的答案沒有SortDescriptions,所以我回答了它,你編輯包括 – xdumaine 2011-04-07 18:34:03