在Windows Phone中使用RightTapped获取项目(Get item in listview using RightTapped in Windows Phone)

系统教程 行业动态 更新时间:2024-06-14 16:58:30
在Windows Phone中使用RightTapped获取项目(Get item in listview using RightTapped in Windows Phone)

我已经知道如何使用ItemClick事件在listview中获取项目。 查看此主题: 在ListView Windows Phone中获取项目

现在,我也想使用RightTapped获取我的列表视图中的项目。

感谢你的帮助。

谢谢!

I already know how to get item in listview using ItemClick event. See this thread: Get Items in ListView Windows Phone

Now, I also wanted to get the item in my listview using RightTapped.

Appreciate your help.

Thanks!

最满意答案

对于RightTapped事件,您可以接收RightTappedRoutedEventArgs对象。 从这里你可以得到正确的ListViewItemPresenter ,你应该可以通过它的DataContext获取该项目。 代码如下:

private void listViewDirectory_RightTapped(object sender, RightTappedRoutedEventArgs e) { ListViewItemPresenter itempresenter = e.OriginalSource as ListViewItemPresenter; Person obj = (Person)itempresenter.DataContext; Debug.WriteLine(obj.Name); }

如果你不想使用ListViewItemPresenter , FrameworkElement也可以工作。

FrameworkElement itempresenter = e.OriginalSource as FrameworkElement; Person obj = (Person)itempresenter.DataContext; Debug.WriteLine(obj.Name);

For RightTapped event you can receive RightTappedRoutedEventArgs object. From this you can get the right tapped ListViewItemPresenter and you should be able get the item by its DataContext. Code as follows:

private void listViewDirectory_RightTapped(object sender, RightTappedRoutedEventArgs e) { ListViewItemPresenter itempresenter = e.OriginalSource as ListViewItemPresenter; Person obj = (Person)itempresenter.DataContext; Debug.WriteLine(obj.Name); }

If you don't want use ListViewItemPresenter, FrameworkElement also worked.

FrameworkElement itempresenter = e.OriginalSource as FrameworkElement; Person obj = (Person)itempresenter.DataContext; Debug.WriteLine(obj.Name);

更多推荐

本文发布于:2023-04-15 03:36:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/c6cb664425dc472f4e2c0fe63e23d7a2.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:项目   Phone   Windows   RightTapped   listview

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!