Net Maui how to reset collectionview selected event ?

Sami 966 Reputation points
2024-01-16T08:47:23.28+00:00

Net Maui how to reset collectionview selected event ? I have created 2 group collectionview menu. When you select the other menu item on collectionview . Also when other menu item selected that I would like to have reset collectionview's selected event when select the other menu item's selected event ? on windows Paltform

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

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 79,546 Reputation points Microsoft Vendor
    2024-01-17T03:15:29.15+00:00

    Hello,

    MAUI do not have reset event method to do it, but if you can make the selected item to null to reset the selected item. For example, we have two Collectionviews. I add SelectionChanged event for these two Collectionviews. if the Collectionview1 item selected, Collectionview2 selected item will be set null, vice versa. You can refer to the following code. As Note: My SelectionMode of Collectionview is Single.

    public YourPage()
    {
         InitializeComponent();
        
         MyCollectionview1.SelectionChanged += MyCollectionview1_SelectionChanged;
         MyCollectionview2.SelectionChanged += MyCollectionview2_SelectionChanged;
    }
    
    
    private void MyCollectionview2_SelectionChanged(object? sender, SelectionChangedEventArgs e)
    {
         if (e.CurrentSelection != null )
         {
             if (e.CurrentSelection.Count==0)
             {
                 return;
             }
             if (MyCollectionview1.SelectedItem == null)
             {
                 return;
             }
             else
             {
                 MyCollectionview1.SelectedItem = null;
             }
         }
    
    
    }
    
    
    private void MyCollectionview1_SelectionChanged(object? sender, SelectionChangedEventArgs e)
    {
         if (e.CurrentSelection!= null)
         {
             if (e.CurrentSelection.Count == 0)
             {
                 return;
             }
             if (MyCollectionview2.SelectedItem == null)
             {
                 return;
             }
             else
             {
                 MyCollectionview2.SelectedItem = null;
             }
         }
    }
    

    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 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.