I’m using an observable collection to hold all files dragged into a ListBox control and binding the collection to the itemssource, now I am using an extended selection mode so I can select more than one item in the ListBox, my problem is if I have selected index 0, 4 and 7 as an example, how could I bring these values up into an array?
I’m using an observable collection to hold all files dragged into a ListBox control
Share
As there is no way to bind to the
SelectedItemsproperty of theListBoxcontrol, you will need to watch for this in the back-end (either ViewModel or code-behind).Depending on when you want this to happen would depend on your approach.
If you want the indexes to be updated
OnSelectionChangedyou will need to hook that event either using an event handler, or using the AttachedCommandBehaviour approach.To get the indexes (collection index, not necessarily display index) you will then loop through the SelectedItems collection and get the
IndexOfvalue from theItemsSourcecollection (in your case theObservableCollection).If your list has been sorted after setting the
ItemsSourceyou may need to take a different approach, however.