my first question, so please be gentle. I have tried for several days to figure it out. The closest I got was to programmatically access the content of the cell in the code behind. Is there a way to do it in the xaml?
For instance, this doesn't work
<Style x:Key="ComboBox" TargetType="DataGridCell">
<Setter Property="FontSize" Value="14"/>
<Setter Property="FontWeight" Value="SemiBold"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
</Style>
<DataTemplate x:Key="foo">
<Border Margin="3">
<DataGrid Style="{StaticResource DGStyle}" Block.TextAlignment="Center">
<DataGrid.Columns>
<DataGridComboBoxColumn Header="bar" SelectedItemBinding="{Binding ListofIntegers, Mode=TwoWay}"
ItemsSource="{Binding Source={StaticResource fooItem}, Path=ListofBar, Mode=OneWay}" CellStyle="{StaticResource ComboBox}" TextBlock.TextAlignment="Center"/>
</DataGrid.Columns>
</DataGrid>
</Border>
</DataTemplate>
I have tried a few other things, having been able to center the headers, and textboxes in textbox columns. The comboboxes are not wanting to cooperate with me though. Any one know how?
Edit: Ok, feel stupid now, was playing around with Andy's solution and stumbled on this
<Style x:Key="BasicComboBox" TargetType="ComboBox">
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="ItemContainerStyle">
<Setter.Value>
<Style TargetType="ComboBoxItem">
<!--can mess with appearance of drop down menu here-->
</Style>
</Setter.Value>
</Setter>
</Style>
<DataGridComboBoxColumn Header="Size" HeaderStyle="{StaticResource Header}" SelectedItemBinding="{Binding Size.Name, Mode=TwoWay}"
ItemsSource="{Binding Source={StaticResource InsertSizes}}" EditingElementStyle="{StaticResource BasicComboBox}"/>
Can set the style of the generated combobox in EditingElementStyle.
Edit 2: While the above works, I think I'm going to go with Andy's suggestion of using a template column, the comboboxes don't blend in with the grid as well, but are much easier for the user to select, as there is no need to open editing mode.