我在 datagrid 中有一个 datagridCombox 列。为了使组合框始终像组合框一样显示(单击或不单击),组合框的实现方式如下
xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit"
<dg:DataGridTemplateColumn Header="Time Unit" x:Name="timeUnit" >
<dg:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox SelectedValue="{Binding RelParams.TimeUnit}"
Background="White" BorderBrush="{x:Null}"
ItemsSource ="{Binding TimeUnitList}" >
</ComboBox>
</DataTemplate>
</dg:DataGridTemplateColumn.CellTemplate>
</dg:DataGridTemplateColumn>
现在的问题是 datagridrow 有交替背景。我希望 datagridrow 中的组合框使用与 datagridrow 中的文本框列相同的背景。Also when the datagridrow is selected, the combobox should be highlighted in the same color as the rest of the row. 如何做到这一点?谢谢
<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>