如何创建一个上下文菜单,当用户右键单击我的树视图的元素时将显示该菜单?
我想获取被点击的项目的名称,这怎么可能?
这是我的树视图:
<TreeView Name="tvwResultados"
MouseMove="DataGrid_MouseMove"
MouseLeftButtonDown="DataGrid_PreviewMouseLeftButtonDown"
ItemTemplate="{StaticResource empresaTemplate}"
ItemsSource="{Binding Empresas}"
Padding="0,6,0,6"
Background="Black"
BorderBrush="Gray"
BorderThickness="1">
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Padding" Value="4,2,4,2" />
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="BorderBrush" Value="Gray" />
</Trigger>
</Style.Triggers>
</Style>
</TreeView.ItemContainerStyle>
<TreeView.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#171717" />
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Silver" />
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="#333333" />
<SolidColorBrush x:Key="{x:Static SystemColors.ControlTextBrushKey}" Color="Silver" />
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="Gray" />
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}" Color="Silver" />
</TreeView.Resources>
</TreeView>