简体   繁体   English

将可观察的集合绑定到GridView

[英]Binding Observable Collection to a GridView

<GridView  SelectionMode="None" x:Name="InvoiceContainer" CanReorderItems="True" 
 ItemTemplate="{StaticResource ItemTemplate2}" ItemsSource="{Binding SecondCollection}"
/>

I'm Using windows Store apps. 我正在使用Windows应用商店应用。 I have used an observable collection to bind data to the grid view. 我使用了一个可观察的集合将数据绑定到网格视图。 I need to bind all items in reverse order. 我需要以相反的顺序绑定所有项目。

ex item 3, item 2, item 1 instead of item 1, item 2, item 3 例如项目3,项目2,项目1,而不是项目1,项目2,项目3

You will need to sort the collection before binding. 绑定之前,您需要对集合进行排序。 You can use LINQ to create a newly ordered collection. 您可以使用LINQ创建新排序的集合。 Assuming your data items have a "Name" element you want to sort on you can do the following: 假设您的数据项具有要排序的“名称”元素,则可以执行以下操作:

data = new ObservableCollection<DataItem>(data.[OrderByDescending][1](d => d.Name));

It's not built-in, but there are extended versions of CollectionViewSource which support sorting. 它不是内置的,但是CollectionViewSource的扩展版本支持排序。 I can't vouch for any specifically, but a quick search for CollectionViewSource Sort WinRT found several that look promising. 我不能提供任何具体保证,但是快速搜索CollectionViewSource Sort WinRT发现了一些看起来很有希望的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM