I'm trying to implement the following code, with the difference that I would like this to apply to a style so that I can set it for any ComboBox
that I like (i.e. I am creating a number of ComboBoxes dynamically from the code behind due to specific unchangeable requirements, and would like to add GroupStyles
to each of them).
I am relatively new to WPF
and XAML
, so I thought of doing so through a Style
and specifying the GroupStyles
in the ControlTemplate
, and then just applying the style to the respective ComboBoxes
. This is what I've tried so far, but the code will not compile (mainly due to the <ComboBox.GroupStyle>
part).
<Style x:Name="valuesComboStyle" TargetType="ComboBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<ComboBox.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ComboBox.GroupStyle>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>