我有这个数据网格(见图片)而且我真的想在特定列上有一个右键菜单,请看红色方块。但它应该只是具有菜单的单元格。我在网上搜索过,但我只能在那里找到它的标题而不是列。
这是单元格代码:
<DataGridTextColumn Header="{wpfTx:Translate Action}" Binding="{Binding Action}" IsReadOnly="false" Width="*">
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="TextWrapping" Value="Wrap" />
</Style>
</DataGridTextColumn.ElementStyle>
<DataGridTextColumn.EditingElementStyle>
<Style TargetType="{x:Type TextBox}">
<Setter Property="TextWrapping" Value="Wrap" />
<Setter Property="AcceptsReturn" Value="true" />
</Style>
</DataGridTextColumn.EditingElementStyle>
</DataGridTextColumn>
请帮帮我:)。
答案 0 :(得分:1)
更改样式,以便触发器添加上下文菜单。像这样:
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="TextWrapping" Value="Wrap" />
<Style.Triggers>
<DataTrigger Binding="{Binding Action}" Value="Whatever">
<Setter Property="ContextMenu">
<Setter.Value>
<ContextMenu>
<MenuItem Header="Cut" />
<MenuItem Header="Copy" />
</ContextMenu>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.ElementStyle>
<DataGridTextColumn.EditingElementStyle>
<Style TargetType="{x:Type TextBox}">
<Setter Property="TextWrapping" Value="Wrap" />
<Setter Property="AcceptsReturn" Value="true" />
<Style.Triggers>
<DataTrigger Binding="{Binding Action}" Value="Whatever">
<Setter Property="ContextMenu">
<Setter.Value>
<ContextMenu>
<MenuItem Header="EditingCut" />
<MenuItem Header="EditingCopy" />
</ContextMenu>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.EditingElementStyle>