Issue with Pre-selection

Manickam, Suraj 320 Reputation points
2024-02-15T10:54:06.42+00:00

I need to preselect the list if it has only one item , i tried the one suggested in the MAUI official docs but it never seemed to work for me . I tried by manually setting the following in the constructor of the code behind of the view, if(viewModel.list.count==1) collectionView.SelectedItem=viewModel.list[0]; But it does not preselect it , is there any other way?

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,231 questions
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 72,251 Reputation points Microsoft Vendor
    2024-02-23T07:56:03.99+00:00

    Hello,

    Please do not initialize multiple times in ItemSource, it will make Pre-selection not working.

    By the way, for windows, there is a known issue reported at GitHub- Custom selection styles for items in CollectionView are ignored when programmatically selecting an item · Issue #18933 · dotnet/maui (github.com) .

    Thanks for your update.

    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.


0 additional answers

Sort by: Most helpful