ElementStyle in this case must be of type ComboBox . We have two types of DataGrid that it uses - DataGridRow and DataGridCell , the first is a row, the second cell. Therefore, by default, everything consists of cells of type DataGridCell not TextBlock's .
To determine the type of another column, use a DataGridTemplateColumn . Therefore, a DataGridComboBoxColumn can be defined as:
<DataGridTemplateColumn Width="1.5*" IsReadOnly="False" Header="Position2"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <ComboBox x:Name="ComboBoxColumn" /> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn>
There can be any type of control with this kit.
In your case, you need to create a style for the DataGridCell :
<Style x:Key="StyleForCell" TargetType="{x:Type DataGridCell}"> <Setter Property="Background" Value="Green" /> </Style>
And using like this:
<DataGridComboBoxColumn x:Name="ComboBoxColumn" CellStyle="{StaticResource StyleForCell}" Header="Position" SelectedItemBinding="{Binding Position}" />
source share