wp8 listbox绑定数据后响应tap或其他时间
我使用listbox数据绑定,需实现长按item然后出来delete菜单,然后删除这个item的功能,我使用了<toolkit:ContextMenu>
<toolkit:MenuItem Header="delete" Click="MenuItem_Click/>
</toolkit:ContextMenu>
然后响应消息
private void MenuItem_Click(object sender, RoutedEventArgs e)
{
menuitem = (MenuItem)sender;
}
可是,问题是这个传进来的sender是空的,command=null,commandparater=null,所以我获取不到selectedItem.
请问这是什么原因,该怎样解决.
而且我试着加tap事件,sender也是空的:
<ListBox x:Name="ListBox ItemsSource="{Binding}" Tap="MainLongListSelector_Tap_1">
private void MainLongListSelector_Tap_1(object sender, System.Windows.Input.GestureEventArgs e)
{
}
请问是不是要用
<i:Interaction.Triggers>
<i:EventTrigger EventName="Tap">
<i:InvokeCommandAction Command="{Binding Main.TapCommand}" CommandParameter="{Binding }" />
</i:EventTrigger>
</i:Interaction.Triggers>
可是我不回加这种事件。
以下是我的xaml
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,238,12,0">
<ListBox x:Name="MainList" Margin="0,0,-12,0" ItemsSource="{Binding }" SelectionChanged="MainList_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,17">
<TextBlock Text="{Binding Name}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
<TextBlock Text="{Binding Adress}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
<!-- -->
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu>
<toolkit:MenuItem Header="delete" Click="MenuItem_Click"/>
<toolkit:MenuItem Header="edit" Click="MenuItem_add"/>
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
[解决办法]
加上CommandParameter="{Binding}"