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