0

There is an itemscontrol in one of my views that lets the user reorder the items by an up/down button.

My question is on how I can flow the current index of the items to my viewmodel

The following questions address on how to find the current index (not so clean but it does the job)

WPF - Bind to Item Index from within ItemTemplate of ItemsControl?

Now, how can I modify the XAML so that it binds this index to a property on my viewmodel?

edit The question is about how to do it in XAML declaratively. A possible solution is to do it in code using and ObservableCollection and subscribe to CollectionChanged

Kind Regards, Tom

Community
  • 1
  • 1
buckley
  • 13,690
  • 3
  • 53
  • 61

1 Answers1

0

So your items store an index poperty that you need to update when they are re-ordered in the UI?

I would create a view model that exposes my items as an ObservableCollection. You can then handle the CollectionChanged event which will fire when the items are re-ordered in your view model. At this point you can enumerate the collection of items updating their indices.

ColinE
  • 68,894
  • 15
  • 164
  • 232
  • Hello ColinE. Good answer and I have went that rout after I could found a way to do it in the XML through databinding. The question is about how to do it in XAML declaratively. – buckley Sep 02 '11 at 13:59