首先,我知道这个主题:如何使上下文菜单适用于Windows Phone?
但这种方式很复杂......所以我有这个XAML代码:
<StackPanel Name="friendsGrid" Margin="0,0,0,0" Background="Transparent">
<ListBox Name="friendsListBox" FontSize="32" Tap="friendsListBox_Tap">
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu Name="MyContextMenu" Opened="MyContextMenu_Opened">
<toolkit:MenuItem Header="action" Click="contextMenuAction_Click"/>
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
</ListBox>
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
我正在填写这样的列表:
this.friendsListBox.Items.Add(friend.serviceName);
Run Code Online (Sandbox Code Playgroud)
但是,当然,当我执行longtap时,会出现上下文菜单并选择整个List,而不仅仅是一个项目.
是否有一些简单的方法来识别项目被轻敲?谢谢
顺便说一句,我找到了这个方法,但contextMenuListItem没有收到任何东西,它仍然是null:
ListBoxItem contextMenuListItem = friendsListBox.ItemContainerGenerator.ContainerFromItem((sender as ContextMenu).DataContext) as ListBoxItem;
Run Code Online (Sandbox Code Playgroud)