I have a CollectionView and which consists of a list of items. I can't figure out a way to bind the multiple selected items to a list in the ViewModel.
XAML Code:
<CollectionView ItemsSource="{Binding Names}" SelectedItems="{Binding NamesSelection}" SelectionMode="Multiple">
<CollectionView.ItemTemplate>
<DataTemplate>
<StackLayout>
<Label Text="{Binding Name}" VerticalOptions="Center"/>
</StackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
Nonfunctional ViewModel Code:
public MvxObservableCollection<Name> Names { get; } = new MvxObservableCollection<Name>(NamesHelpers.GetObjects());
private MvxObservableCollection<Name> _namesSelection;
public MvxObservableCollection<Name> NamesSelection
{
get=> _namesSelection;
set
{
SetProperty(ref _namesSelection, value);
}
}
This would probably work if I had a SelectedItem clause. But I'm not sure how to get it working for SelectedItems.
Ideal output would be for the NamesSelection List to populate/depopulate based on the selected items.