Xamarin.Forms
Xamarin.Forms copied to clipboard
[UWP] Cannot unselect SelectedItem for CollectionView
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;
}
}
Steps to Reproduce
- Create a SelectedItem property
- Create a SelectionChangedCommand
- Fill a CollectionView
- 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
I have tried to reproduce the issue. Using SelectionChangedCommand
command I set SelectedItem
to null after one second.
What Xamarin.Forms version are you using?
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
i am still facing this issue. I tried to:
- Set selected item to null
- Clear the list
- set the whole list to null
- set it to a new empty observable collection.
Nothing works. Only recreating the whole page reset the selection. I am using Xamarin forms version: 5.0.0.2012
Surprisingly, a simple Task.Delay(5000)
resolved this issue for me as @jsuarezruiz mentioned.
await Task.Delay(5000); RecommandedAttendeesList.SelectedItem = null;
I was able to reduce that delay to 50ms. That's mostly undetectable. It would be nice if this issue is properly addressed but it's a great workaround you found! saved my life!
Adding a timer like that isn't a fix. It's a bad workaround that isn't production grade. We need a real workaround or real fix.
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; } }
Steps to Reproduce
- Create a SelectedItem property
- Create a SelectionChangedCommand
- Fill a CollectionView
- 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
Use OnPropertyChanged(); on SelectedItem.
See this https://learn.microsoft.com/en-us/answers/questions/221399/collectionview-deselection
public Monkey SelectedMonkey { get { return selectedMonkey; } set { if (selectedMonkey != value) { selectedMonkey = value; OnPropertyChanged(); } } }