user8001246
user8001246

Reputation:

2 Different ComboBox Styles with 2 Different ComboBoxItem Styles

I have 2 ComboBox-Styles in my WPF-Application. They're look both like this:

<Style TargetType="{x:Type local:MyComboBox1}">
    <Style.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                ...
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Style.Resources>
    <Setter Property="SnapsToDevicePixels" Value="true" />
    ...
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:MyComboBox1}">
             ...
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    <Style.Triggers />
</Style>

Now I want to style the ComboBoxItems for each ComboBox in a different way. How can i do this?

Upvotes: 0

Views: 205

Answers (1)

NtFreX
NtFreX

Reputation: 11357

You can use the ItemContainerStyle property

<Style TargetType="Combobox" x:Key="myStyleOne">
    <Setter Property="ItemContainerStyle">
        <Setter.Value>
            <Style TargetType="ComboBoxItem">

                <!-- put your style here -->

            </Style>
        </Setter.Value>
    </Setter>
</Style>

And then you can use your style like the following.

<ComboBox Style="{StaticResource myStyleOne}" />

Upvotes: 1

Related Questions