I'm having trouble working with the List View setup to Bind Multiple Selections and remember the selections when I switch the Selection Mode to between Single and Multiple.
Context
I'm creating a Soccer coaching app. The List View will display the Player Roster. On game day, I want an easy way to select the players that showed up to play. I would like to use the Multiple Selection mode to allow the user to select the players that showed up. I will provide a button in the app bar that will control the SelectionMode through a converter. It will switch the List View from Single to Multiple. This part works fine. I can see the List View switch between Single and Multiple.
The part that doesn't work fine is the binding of Selected Items. I must be missing something because it seems extremely difficult to bind to the SelectedItems property reliably. The best thing that has worked so far is the ListViewExtentions from the WinRTXamlToolkit which is what I show in my xaml below. It seems to bind the items to the backing property in the view mode when the selection is made, however, when the SelectionMode is switched back to Single, the back property is cleared out. Also, without modifying the extension code, it broke my SelectionMode code. There is a castastrophic failure in the extension on _listView.SelectedItems.Clear(). If I remove that line, then SelectionMode is back working.
I don't care to use the ListViewExtentions from WinRTXamlToolkit. I only present it here so you know that I have tried it. Ultimately, I'm looking for the right solution for binding SelectedItems.
Here is the List View XAML.
<ListView ItemsSource="{Binding Roster}"
toolkitExt:ListViewExtensions.BindableSelection="{Binding SelectedPlayers, Mode=TwoWay}"
SelectionMode="{Binding IsEditingGameRoster, Converter={StaticResource ListViewSelectionModeFromBooleanNoneOrMultipleConverter}}">
<ListView.ItemTemplate>
<DataTemplate>
<!-- List View Display Not important for describing problem. -->
</DataTemplate>
</ListView.ItemTemplate>
Namespace is: xmlns:toolkitExt="using:WinRTXamlToolkit.Controls.Extensions"
The View Model has the properties: Roster : ObservableCollection IsEditingGameRoster : Bool SelectedPlayers : ObservableCollection
Thanks for any samples that demonstrate binding Multiple Selection especially if it handles switching SelectionMode as well.
Thanks, Tom