For a ListView where I can select multiple items from the list, my method for the selected Index will be called if I’m selecting one item. But I I select more than one at a time my ‘TheSelectedIndex’ method is not being called. I want it to be called for any type of selection. zero items, 1 item ore more than 1 item. How do I set it up for that? Thank you very much!
<ListView
SelectionMode="Multiple"
SelectedIndex="{Binding Path="TheSelectedIndex}"
ItemsSource="{Binding Path=Object}">
One way to handle this is to ensure that the type to which you bind the ItemsSource property exposes an IsSelected property. This may mean wrapping that type into a custom ViewModel class that simply exposes the underlying type and adds an IsSelected property.
Once you introduce the concept of selection state to the individual items in the bound collection, you can leverage the ListView.SelectionChanged event and some code-behind to access the view-model (assumes you’re using MVVM, which I think you are, considering your bindings):
In XAML…
In code-behind…
In view-model…
In SomeType, which is a view-model wrapper for each item in the collection…