我的 ContextMenu 有一点问题,有时单击 ContextMenu 时未在 LongList 中选择该项目,这给了我一个问题,即我不知道用户单击了哪个项目。如果我先单击该项目,然后按住上下文菜单,它会起作用,但是每次用户单击并按住时,我怎样才能使它起作用?
这是我的xml
<phone:LongListSelector x:Name="List"
Margin="0,0,-12,0"
ItemsSource="{Binding ListItems}"
Height="470" Tap="List_OnTap">
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,17">
<TextBlock Text="{Binding Name}"
TextWrapping="Wrap"
Style="{StaticResource PhoneTextExtraLargeStyle}">
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu IsZoomEnabled="false">
<toolkit:MenuItem Header="Add as favorit"
Click="AddFavorite" />
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
</TextBlock>
</StackPanel>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
我的代码在后面
private void AddFavorite(object sender, RoutedEventArgs e)
{
ItemViewModel obj = List.SelectedItem as ItemViewModel;
if (obj == null) return;
NavigationService.Navigate(new Uri("/Page.xaml?id=" + obj.Id + "&fav=true", UriKind.Relative));
}