我有以下上下文菜單:Silverlight上下文菜單:如何確定點擊了哪個菜單?
<ListBox x:Name="sectionList" Margin="56,8,15,0" FontSize="64" SelectionChanged="SectionList_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu>
<toolkit:MenuItem Header="Hide this section from this list" Click="ContextMenuItem_Click" />
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
<TextBlock Text="{Binding DisplayName}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
正如你所看到的,每個顯示的項目都有自己的上下文菜單。每個上下文菜單掛在同一個事件處理:
private void ContextMenuItem_Click(object sender, RoutedEventArgs e)
{
}
從這個方法,我怎麼能告訴單擊的上下文菜單?我想知道對應的DataTemplate
的DataContext
是什麼。