準備教程。
1. 無難度方式
<DataTemplate x:Key="DataTemplate1">
<StackPanel >
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu >
<toolkit:MenuItem Tag="{Binding}" Click="MenuItem_Click" />
private void MenuItem_Click(object sender, RoutedEventArgs e)
{
MenuItem item = sender as MenuItem;
A rd = item.Tag as A;
}
2.command摸索中 此時拿到的事整體的資料來源
<DataTemplate x:Key="DataTemplate1">
<StackPanel >
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu >
<toolkit:MenuItem Command="{Binding MyCommand}" CommandParameter="{Binding}" >
<toolkit:MenuItem.DataContext>
<listdata:ViewModel/>
</toolkit:MenuItem.DataContext
3.此時效果與1相同
<DataTemplate x:Key="DataTemplate1">
<StackPanel >
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu >
<toolkit:MenuItem Command="{Binding DataContext.MyCommand, ElementName=LayoutRoot}" />