Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unselect GridView.Item on click if already selected

I know this seems rather simple, and that's what I thought too, but it actually isn't. I have a GridView, with SelectionMode="Single", and I want to simply unselect a selected item by clicking on it. Problem is, SelectionChanged doesn't fire when you select an item that is already selected. I've tried having an int equal to the GridView's SelectedIndex on each SelectionChanged, and then check on Grid_Tapped to see if PreviousSelectedIndex == CurrentlySelectedIndex, but the SelectionChanged event fires nanoseconds before the Grid_Tapped, so it doesn't work. Any ideas?

like image 789
user2950509 Avatar asked Mar 14 '23 19:03

user2950509


1 Answers

I think instead of Delay its better to use this:

Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => gridView.SelectedItem = null);
like image 119
Mike Tsayper Avatar answered Mar 24 '23 14:03

Mike Tsayper