LongListSelector: Item tap?

后端 未结 6 732
执念已碎
执念已碎 2020-12-02 20:39

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 SelectionChang

6条回答
  •  一向
    一向 (楼主)
    2020-12-02 20:52

    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):

    MyListItemClass item = ((FrameworkElement)e.OriginalSource).DataContext 
                                                                 as MyListItemClass;
    

    Also, you could get the original item ContentPresenter simple by navigating up through VisualTree from e.OriginalSource. That way:

    ContentPresenter itemPresenter = SomeHelperClass
                                  .FindParent(e.OriginalSource,"");
    

    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).

提交回复
热议问题