WPF ItemsControl绑定和项目顺序

时间:2023-01-19 09:08:00

I have ItemsControl in a WPF application, which is bind to an array of objects. And I am using ItemTemplate to render the list. I want to display for each item in the list the item order, like for example

我在WPF应用程序中有ItemsControl,它绑定到一个对象数组。我正在使用ItemTemplate来呈现列表。我想为列表中的每个项目显示项目顺序,例如

Customer 1 Name : xxxxx Age: 9999

客户1姓名:xxxxx年龄:9999

Customer 2 Name : yyyy Age: 8888

客户2姓名:yyyy年龄:8888

Any idea how to do it Thanks

任何想法如何做到谢谢

1 个解决方案

#1


5  

I think what you are asking is how to sort your ItemsSource property when displaying it in an items control?

我想你问的是如何在items控件中显示ItemsSource属性时对它进行排序?

You can do this by using a CollectionViewSource. The CollectionViewSource gives you the ability group and / or sort your ItemsSource. It does this by creating a "view" which is a separate copy of your items source with your grouping and sorting applied to it.

您可以使用CollectionViewSource执行此操作。 CollectionViewSource为您提供了能力组和/或排序您的ItemsSource。它通过创建“视图”来实现此目的,该视图是项目源的单独副本,其中应用了分组和排序。

This allows you to show your data in multiple different groupings or sortings on the same page while still only having one underlying source collection.

这允许您在同一页面上的多个不同分组或排序中显示数据,同时仍然只有一个基础源集合。

#1


5  

I think what you are asking is how to sort your ItemsSource property when displaying it in an items control?

我想你问的是如何在items控件中显示ItemsSource属性时对它进行排序?

You can do this by using a CollectionViewSource. The CollectionViewSource gives you the ability group and / or sort your ItemsSource. It does this by creating a "view" which is a separate copy of your items source with your grouping and sorting applied to it.

您可以使用CollectionViewSource执行此操作。 CollectionViewSource为您提供了能力组和/或排序您的ItemsSource。它通过创建“视图”来实现此目的,该视图是项目源的单独副本,其中应用了分组和排序。

This allows you to show your data in multiple different groupings or sortings on the same page while still only having one underlying source collection.

这允许您在同一页面上的多个不同分组或排序中显示数据,同时仍然只有一个基础源集合。