I have a grid with DataGridComboBoxColumn and I am trying to change the foreground color of the cell (not in edit state).
I know that I can workaround this using DataGridTemplateColumn but I'd like to try this.
Compare:
<DataGridComboBoxColumn Header="Is Active"
SelectedItemBinding="{Binding IsActive}"
EditingElementStyle="{StaticResource ComboBoxStyle}"
ItemsSource="{StaticResource BooleanValues}">
</DataGridComboBoxColumn>
and
<DataGridTemplateColumn Header="IsActive">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding IsActive}"
Style="{StaticResource DataGridTextBlockStyle}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<Grid FocusManager.FocusedElement="{Binding ElementName=combo}">
<ComboBox Name="combo"
SelectedValue="{Binding IsActive}"
ItemsSource="{StaticResource BooleanValues}" />
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
Thanks for hints!
You can define your DataGridComboBoxColumn CellStyle :
<DataGridComboBoxColumn Header="Is Active"
SelectedItemBinding="{Binding IsActive}"
EditingElementStyle="{StaticResource ComboBoxStyle}"
ItemsSource="{StaticResource BooleanValues}">
<DataGridComboBoxColumn.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="Foreground" Value="Red" />
</Style>
</DataGridComboBoxColumn.CellStyle>
</DataGridComboBoxColumn>

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With