-1

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

Customer 1 Name : xxxxx Age: 9999

Customer 2 Name : yyyy Age: 8888

Any idea how to do it Thanks

Ghassan Karwchan
  • 3,355
  • 7
  • 37
  • 65

1 Answers1

5

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

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.

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.

Brad Cunningham
  • 6,402
  • 1
  • 32
  • 39
  • Your answer is spot on... It wouldn't be the OP himself doing this? It happened to a correct answer on his other question as well... – Dabblernl Nov 28 '09 at 14:58
  • 1
    @Foovanadil, I agree with you, sometimes kids just put down vote because they can and they like, and no one asks for any explanation. I think comment on downvote should be compulsory. – Akash Kava Nov 29 '09 at 07:11
  • Totally agree. I think if you are going to down vote something you should explain yourself. I know I do if I down vote something – Brad Cunningham Nov 30 '09 at 04:38
  • @AkashKava and Brad Connungham, maybe you would be interested in this thread of Meta: http://meta.stackexchange.com/questions/144851/select-from-list-of-reasons-when-performing-downvotes/172547#172547 – Dzyann Jan 16 '14 at 20:51