I have a DataGridCheckBoxColumn that I want to set the background color of the checkbox to indicate that it is readonly. I have figured out how to set the entire cell background color using a CellStyle tag, however, I can't figure out what I need to do to target the checkbox's background color, and not the entire data cell.
Below is what I have, which sets the color of the DataGridCell, not the checkbox. I seem to be getting exception if I have anything as the TargeType
besides DataGridCell
.
<DataGridCheckBoxColumn Header="Processed" Binding="{Binding Path=IsProcessingComplete, Mode=OneWay}" Width="70" IsReadOnly="True">
<DataGridCheckBoxColumn.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="Background" Value="Gray"/>
开发者_JAVA百科 </Style>
</DataGridCheckBoxColumn.CellStyle>
</DataGridCheckBoxColumn>
Try to use DataGridTemplateColumn
. I think that it would be easier than DataGridCheckBoxColumn
to set the `Background'.
<DataGrid ItemsSource="{Binding}" >
<DataGrid.Columns>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox Background="Red"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
精彩评论