4
votes

I'm creating an WP7-app with a PhoneApplicationPage containing a ListBox.
When the user selects an item in the ListBox another page will be opened.

Now I'm confused a bit: Which ListBox event handler should I use to detect the selection, Tap or SelectionChanged? And how do I get the tapped item in case of Tap?

3

3 Answers

6
votes

I would suggest you use the SelectionChanged event, this will always register in the correct way if an item is clicked.

A benefit of using the SelectionChanged event is that you will get SelectionChangedEventArgs which contains useful information.

A important thing to do however is to reset the selected index back to -1 when an item has been clicked, otherwise when the user comes back to the page that item is still selected and the item won't be clickable.

2
votes

Just to add on to the other answers, you must also make a null check in your SelectionChanged event, because when you make selected index = -1, it triggers the SelectionChanged event too.

1
votes

There is one problem with the SelectionChanged event. If you select an item and gets sent to a new page and goes back again, you can't select the same item again because it only works when the selection is changed :). Just keep that in mind