17

A ListView in Xamarin.Forms has two events, which seem to be exactly the same: ItemTapped and ItemSelected

There isn't really any documentation about these, so what exactly is the difference?

5 Answers 5

18

ItemSelected is a state while ItemTapped is a motion event. All views can be tapped and if I remember correctly all views can be selected (or at least activated there is a subtle difference), the two don't have to go together but they usually do.

For example you'd have an item's selected state toggled each time a tapped motion event has occurred. Once again just to make it more clear you can associate the changes of the selected state to whatever you need whether it's a motion event like tapping or long pressing or double tapping and so on or to some other event or logic.

Hope it helps and good luck!

1
  • 1
    How can you implement a long press in a list view with xamarin.forms? Commented Jul 2, 2014 at 17:06
13

ItemTapped should occur every time you click on an item, while ItemSelected every time the selected item has changed.

Basically

  • tapping two times the same item should fire two times ItemTapped, and only once ItemSelected
  • tapping two times, on different items, should fire ItemTapped two times, and ItemSelected two times
2
  • Weird, ItemSelected is fired twice in the first case for me.
    – prompteus
    Commented Aug 10, 2016 at 9:19
  • The implementation may change of course with different versions, and platforms. I remember also a 1.x not always firing ItemTapped for Windows Phone. You should raise a bug in bugzilla Commented Aug 11, 2016 at 8:06
1

ItemSelected occurs first. ItemTapped occurs second.

1

One major difference worth noting is how they work when the SelectionMode="None"

<ListView ... SelectionMode="None" />

When set to "None"...the ItemSelect event will not fire and SelectedItem property remains null.

But ItemTapped events will continue to fire as expected.

ListView interactivity

0

I think ItemSelected is when you use the DataTemplate for your items.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.