Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Setting ListView selectedItem to null throws an exception on WP 8.1

$
0
0

I have a page with a listview, when you press the row it takes you to a detail page. When you navigate back you should get the same list without a selected item. If I don't set the selectedItem to null, you can't select the same row again. Setting the SelectedItem to null works as expected on Android and iOS, but it throws an exception on WP 8.1.

My code:

async Task  OnSelection (object sender, SelectedItemChangedEventArgs e)
        {
            var list = ((ListView)sender);
            if (e.SelectedItem == null) {
                return; //ItemSelected is called on deselection, which results in SelectedItem being set to null
            }
            var sessionViewModel = e.SelectedItem as SessionViewModel;
            list.SelectedItem = null;
            await Navigation.PushAsync(new AgendaDetail(sessionViewModel), Device.OS != TargetPlatform.Android);
        }

The exception:

System.ArgumentException: Value does not fall within the expected range.
   at Windows.UI.Xaml.Controls.Primitives.Selector.put_SelectedIndex(Int32 value)
   at Xamarin.Forms.Platform.WinRT.ListViewRenderer.OnElementItemSelected(Object sender, SelectedItemChangedEventArgs e)

Is there another way to clear selected item on WP?


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>