以下是如何在选中单元格时设置背景的示例,但实际上当我点击单元格进行编辑时,颜色会变化。是否有一个触发属性可以在单元格正在被编辑时使用?我希望背景不要改变。
回答自己的问题,看起来单元格背景色基于
<DataGrid Name="DG1" ItemsSource="{Binding}" SelectionUnit="Cell" >
<DataGrid.CellStyle>
<Style TargetType="DataGridCell" >
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="SeaGreen"/>
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.CellStyle>
</DataGrid>
回答自己的问题,看起来单元格背景色基于
SystemColors.WindowBrushKey
。 通过像这样覆盖该资源 <SolidColorBrush x:Key="{x:Static SystemColors.WindowBrushKey}" Color="Red" />
就可以解决这个问题。