Xamarin.forms: [UWP] Cannot unselect SelectedItem for CollectionView

Created on 11 Jul 2020  路  4Comments  路  Source: xamarin/Xamarin.Forms

Description

Unselecting SelectedItem in MVVM by setting the binded property to null does work for iOS and Android for UWP it does not work.

My case: Selecting a Item navigates to another page. After navigating back the selection should be unselected.

SelectionChangedCommand:

        private async void ArticleTeaserCollectionSelectionCommandMethod()
        {
            if(SelectedArticleTeaserItem != null && SelectedArticleTeaserItem != default)
            {
                await Navigation.PushAsync(new FullArticlePage(Navigation, new ArticleTeaser
                {
                    Title = SelectedArticleTeaserItem.Title,
                    ArticleLink = SelectedArticleTeaserItem.ArticleLink,
                    Date = SelectedArticleTeaserItem.Date,
                    TeaserText = SelectedArticleTeaserItem.TeaserText,
                    TeaserImageLink = SelectedArticleTeaserItem.TeaserImageLink
                }), true);

                SelectedArticleTeaserItem = null;
            }
        }

Sample.zip

Steps to Reproduce

  1. Create a SelectedItem property
  2. Create a SelectionChangedCommand
  3. Fill a CollectionView
  4. Clear Selection in SelectionChangedCommand

Expected Behavior

Selection should be cleared for UWP

Actual Behavior

UWP Selection does not clear (iOS and Android works)

Basic Information

Xamarin.Forms 4.7

collectionview 3 UWP bug

Most helpful comment

I'm also experiencing this issue, this also seems related to bug #12491

All 4 comments

I have tried to reproduce the issue. Using SelectionChangedCommand command I set SelectedItem to null after one second.
issue11405
What Xamarin.Forms version are you using?

Sample.zip

@jsuarezruiz Here is a sample. As I wrote I does not work this way I showed.

Same issue but only with Selected VisualSate defined. If VSM not defined on CollectionView, the item is unselected correctly. Related to PR https://github.com/xamarin/Xamarin.Forms/pull/10770

I'm also experiencing this issue, this also seems related to bug #12491

Was this page helpful?
0 / 5 - 0 ratings