WPF,C#, 我有一个包含多列,多行的数据网格。我希望行中的每个单元格具有不同的上下文菜单项。如何在DataGridCell上创建动态上下文菜单
如何做到这一点?谢谢 我有这个
<UserControl.Resources>
<ContextMenu x:Key="cellContextMenu">
<MenuItem x:Name="menuFillUp" Header="Fill _Up" />
</ContextMenu>
<Style x:Key="DataGridCellStyle" TargetType="{x:Type dg:DataGridCell}">
<Setter Property="ContextMenu" Value="{DynamicResource cellContextMenu}" />
</Style>
<Style x:Key="DataGridRowStyle" TargetType="{x:Type dg:DataGridRow}">
<Style.Triggers>
<Trigger Property="AlternationIndex" Value="1" >
<Setter Property="Background" Value="Beige" />
</Trigger>
</Style.Triggers>
<Setter Property="Margin" Value="0 2 0 2" />
</Style>
<Style x:Key="DataGridStyle" TargetType="{x:Type dg:DataGrid}">
<Setter Property="AlternationCount" Value="2" />
<Setter Property="RowStyle" Value="{StaticResource DataGridRowStyle}" />
<Setter Property="CellStyle" Value="{StaticResource DataGridCellStyle}" />
</Style>
</UserControl.Resources>
但这是为数据网格级别。谢谢
请注意:对于我来说DataGridCell的命名空间是'System.Windows.Controls'而不是'Microsoft.Windows.Controls'。 – 2017-06-22 18:46:54