I have a DataGrid containing some DataGridComboBoxColumns.
I would like the comboBoxes inside those columns to have a certain style applied.
so I tried adding the following to my DataGrid's Resources:
<Style x:Key="{x:Type ComboBox}" TargetType="{x:Type ComboBox}">
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
<Se开发者_开发知识库tter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
<Setter Property="Background" Value="{StaticResource DefaultBackgroundBrush}"/>
<Setter Property="BorderBrush" Value="{StaticResource DefaultBorderBrush}"/>
<Setter Property="Foreground" Value="{StaticResource DefaultForegroundBrush}"/>
<Setter Property="FontFamily" Value="{StaticResource DefaultFontFamily}"/>
<Setter Property="FontSize" Value="{StaticResource DefaultFontSize}"/>
<Setter Property="Padding" Value="2"/>
</Style>
does not do anything at all.
amazingly enough, if I add:
<Style x:Key="{x:Type ComboBoxItem}" TargetType="ComboBoxItem">
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="Foreground" Value="Red"/>
</Style>
the comboBoxItems inside the same comboBoxes will get the red foreground color Correctly.
so basically, I cannot set the style of the comboBoxes inside my dataGrid, but I can set the style of the comboBoxItems inside those same comboBoxes.
quite surprising...
does anyone have a clue about what's going on here and how I can solve my problem?
thanks
What exactly is this supposed to do? x:Key="{x:Type ComboBox}"
You should not assign keys if you want styles to be applied to all controls in the subtree.
Edit: To apply the styles to the ComboBoxes you must adjust the properties DataGridComboBoxCotlumn.ElementStyle
and DataGridComboBoxColumn.EditingElementStyle
.
精彩评论