Skip to content

Instantly share code, notes, and snippets.

@ajonno
Created June 27, 2014 03:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajonno/6ae0d2aebfae79d2ec9c to your computer and use it in GitHub Desktop.
Save ajonno/6ae0d2aebfae79d2ec9c to your computer and use it in GitHub Desktop.
how to "reset" a selected row in a ListView --->> when using Xamarin.Forms
listView.ItemSelected += async (object sender, SelectedItemChangedEventArgs e) => {
//Paste this ---v
// Prevents .ItemSelected from running again when SelectedItem is set to null on line below
if (listView.SelectedItem == null)
return;
// Sets the SelectedItem so it can be used by the Switch statement below
var whichCategory = (Category)e.SelectedItem;
// Clears the SelectedItem, this will trigger a 2nd .ItemSelected event which is caught on line above
listView.SelectedItem = null;
//Console.WriteLine("Clicked"); //just for testing when the .ItemSelected event is being triggered
//Paste this--^
switch (whichCategory.Name.ToString())
{
case "item 1":
Navigation.PushAsync(new SomePage());
break;
case "item 2":
Navigation.PushAsync(new SomePage());
break;
case "item 3":
Navigation.PushAsync(new SomePage());
break;
case "item 4":
Navigation.PushAsync(new SomePage());
break;
case "item 5":
Navigation.PushAsync(new SomePage());
break;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment