Search code examples
wpfcomboboxthemesskin

How do I change the skin of the ComboBox?


My English skill is poor because I'm not a native English speaker. I hope you to understand.

I trying to create the style of control to support the skin. Recently, I created a style for ComboBox as shown below.

<Style TargetType="{x:Type ComboBox}" BasedOn="{StaticResource {x:Type ComboBox}}">

    <Setter Property="Background"  Value="Transparent" />
    <Setter Property="Foreground" Value="{DynamicResource ActiveTextBrush}"/>
    <Style.Triggers>
        <Trigger Property="IsEnabled" Value="false">
            <Setter Property="Foreground" Value="{DynamicResource InActiveTextBrush}"/>
        </Trigger>
        <Trigger Property="IsEnabled" Value="true">
            <Setter Property="Foreground" Value="{DynamicResource ActiveTextBrush}"/>
        </Trigger>
    </Style.Triggers>
</Style>

The above code shows the result of the below.

enter image description here

Unfortunately, the result is not what I want. I wanted painting the Background color is to Black but the above code doesn't change Background color.

What I should do to achieve my goal?

Thank you for reading.


Solution

  • Microsoft offers their generic styles and templates for all their core components in WPF framework directly in documentation. Here is the link for ComboBox styles and templates.

    You can grab the XAML code from there (including the common resources at the bottom), adapt it as needed in your app, and add it to your own resources, e.g. App.xaml's Resources.

    (Using Blend for Visual Studio or Visual Studio's own extract style feature, are other options, but in my experience, I found that sometimes these have some quirks/issues with the generated XAML.)