I am using LongListSelector control on Windows Phone 8 and can't figure out the best way to handle a tap on an item. The few examples I've found rely on the SelectionChanged event. However, this solution is buggy because if I tap an item that opens a new page, hit back, and then tap the same item again, it won't work because this item is already selected, so SelectionChanged is not triggered.
I tried to register to the tap event and use the current selected item as the tapped one, but some times the current selected item is not the one I expect.
I could wrap my ItemTemplate in a button and handle the tap for each item but I need to reskin the button to make it look like a simple list item.
Finally, I don't understand why it is so complicated to achieve such a basic thing. Is there a simple and standard way I missed?
My second wish is to get an effect on the item when it is tapped. Is there any standard way to do it?
For this the only thing you need to do add this to your control (or stackpanel where you want to have this effect):
I done it with the Tap event handling.
I prefer not to use Selected property, but get tapped item this way (and I haven't noticed any bugs):
Also, you could get the original item ContentPresenter simple by navigating up through VisualTree from e.OriginalSource. That way:
Where FindParent is similar to find child in this question: How can I find WPF controls by name or type?
ContentPresenter is that object what you need to manually change the item template if you want to (to set "selected" state for example).
You could
null
your LongListSelector'sSelectedItem
at the end of eachSelectionChanged
event. I.e.And the event handler:
You'll fire the SelectionChanged event twice, but nothing's going to happen the second time round and you should get the behaviour that you're looking for - (i.e Setting
SelectedItem
tonull
will trigger a newSelectionChanged
event, but this second event gets caught in the if-statement)As for the second part of your question, you might be better posting a new question.
first add this to *.xaml page inside the
so that it looks like this :
then in the *.xaml.cs file in the event handler
In addition to halil´s answer:
First of all you need to install the Windows Phone Toolkit (WPtoolkit) by NuGet. Than add the namespace declaration on the PhoneApplicationPage.
After this you can add
toolkit:TiltEffect.IsTiltEnabled="True"
to the control definition.It is nice documneted by NOKIA: http://developer.nokia.com/community/wiki/Tilt_Effect_for_Windows_Phone
Oliver