Hello,
You can do this by traversing model.ItemList
, add all items to CollectionView.SelectedItems
, and set SelectionMode = SelectionMode.Multiple
.
For example, I add the x:name for Collectionview like <CollectionView x:Name="collectionView" ItemsSource="{Binding Monkeys}" >
.
Then, if I click the button, I want to select all items in the Collectionview. I need to clear items before add all items. And set SelectionMode = SelectionMode.Multiple
. In the end, I get all items in the viewmodel. Traversing all items and add all items to the collectionView.SelectedItems
.
private void OnCounterClicked(object sender, EventArgs e)
{
collectionView.SelectedItems.Clear();
collectionView.SelectionMode = SelectionMode.Multiple;
foreach (var item in viewModel.Monkeys)
{
collectionView.SelectedItems.Add(item);
}
}
Best Regards, Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.