喜 我得到了下面的树视图,用文本菜单具有以下的MenuItems DoSomeThingOnItem和DoAnotherThingOnItem。
Hi I got the following Treeview, with a ContextMenu with the following MenuItems DoSomeThingOnItem and DoAnotherThingOnItem.
但是,我需要做的,让我得到了项目,其中的ContextMenuItem被点击了?
But what do I need to do, for me to get the Item, where the contextmenuitem was clicked?
<TreeView Name="treeView1" ItemsSource="{Binding Regions}" AllowDrop="True" PreviewMouseRightButtonDown="TreeView1PreviewMouseRightButtonDown">
<TreeView.ItemContainerStyle>
<!-- This Style binds a TreeViewItem to a TreeViewItemViewModel.-->
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="AllowDrop" Value="True" />
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"/>
<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}"/>
<Setter Property="FontWeight" Value="Normal"/>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="FontWeight" Value="Bold"/>
</Trigger>
</Style.Triggers>
</Style>
</TreeView.ItemContainerStyle>
<TreeView.Resources>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type ViewModel:ProductViewModel}"
ItemsSource="{Binding Children}">
<StackPanel Orientation="Horizontal">
<Image Width="16" Height="16" Margin=" 3,0" Source="Images\item.png"/>
<TextBlock Text="{Binding Name}"></TextBlock>
<StackPanel.ContextMenu>
<ContextMenu>
<MenuItem Header="DoSomeThingOnItem"></MenuItem>
<MenuItem Header="DoAnotherThingOnItem"></MenuItem>
</ContextMenu>
</StackPanel.ContextMenu>
</StackPanel>
</HierarchicalDataTemplate>
</TreeView.Resources>
</TreeView>
只是为了更清楚,这是我的文本菜单
Just to make it more clear, here is my contextmenu
<ContextMenu>
<MenuItem Header="DoSomeThingOnItem"></MenuItem>
<MenuItem Header="DoAnotherThingOnItem"></MenuItem>
</ContextMenu>
我已经尝试过的Click事件,但它只是给了我一个
I have already tried with the Click event, but It just gives me a
MenuItem contextMenuItem = (MenuItem)sender;
和我不能想出一个办法来从获得该项目。
And I can't figure out a way to get the item from that.
看看这是相关的: Find一架从树型视图项目从文本菜单
See if this is related: Find Bound Item from TreeViewItem from ContextMenu
上一篇:生成像一个字典中的WHERE语句的字符串字符串、语句、字典、WHERE
下一篇:是内部的类型从Assembly.GetExportedTypes可见的()?类型、Assembly、GetExportedTypes