开发者

How to get index value of Extended Selection Mode WPF ListBox?

开发者 https://www.devze.com 2023-04-01 21:44 出处:网络
I\'m using an observable collection to hold all files dragged into a ListBox control and bindi开发者_开发技巧ng the collection to the itemssource, now I am using an extended selection mode so I can se

I'm using an observable collection to hold all files dragged into a ListBox control and bindi开发者_开发技巧ng 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?


As there is no way to bind to the SelectedItems property of the ListBox control, 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 OnSelectionChanged you 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 IndexOf value from the ItemsSource collection (in your case the ObservableCollection).

If your list has been sorted after setting the ItemsSource you may need to take a different approach, however.

0

精彩评论

暂无评论...
验证码 换一张
取 消