views:

25

answers:

1

I am trying to style a WPF ComboBox so that it matches a black-theme that is being considered for our next project.

My problem is that if the ComboBox's background is black, the button doesn't show up (since it is also black).

For some reason I have not been able to find any information about how to change it's colour.

The following XAML is that I currently have for styling the ComboBox in black:

<ComboBox Name="myComboBox" VerticalAlignment="Top" Width="120"  HorizontalAlignment="Right">
    <ComboBox.Resources>
        <LinearGradientBrush  x:Key="{x:Static SystemColors.HighlightBrushKey}"  StartPoint="0,0" EndPoint="0,1">
            <GradientStop Color="#FFCBCBCB" Offset="0.0"/>
            <GradientStop Color="#FF7C7C7C" Offset="0.3"/>
            <GradientStop Color="black" Offset="1"></GradientStop>
        </LinearGradientBrush>
    </ComboBox.Resources>
    <ComboBox.Background>
        <LinearGradientBrush StartPoint="0,0" EndPoint="0,0.5">
            <GradientStop Color="white" Offset="0"/>
            <GradientStop Color="black" Offset="1"/>
        </LinearGradientBrush>
    </ComboBox.Background>
    <ComboBoxItem Name="cbi1">Item1</ComboBoxItem>
    <ComboBoxItem  Name="cbi2">Item2</ComboBoxItem>
    <ComboBoxItem Name="cbi3">Item3</ComboBoxItem>
</ComboBox>

Any help on the topic would be greatly appreciated.

Thanks,

-Frinny

A: 

You are going to have to modify the ControlTemplate for the ComboBox.

The control itself is surprisingly-at-first-but-not-when-you-think-about-it complex. I would recommend going into Blend (if you have it) and extracting the ControlTemplate. Otherwise, you can get the XAML for a ComboBox using XAMLWriter.

This unfortunately named page (I don't think this is really "Kid's Stuff", do you?) has an example of doing both of these things.

Wonko the Sane
Thank you for the information. Unfortunately I don't have Blend at my disposal (most examples I've found online are using Blend). I will look into the information that you have provided.
Frinavale
Then the second option is probably your best bet. It's a fairly simple process to get the template, but perhaps a more complex process to update it to your means, depending on what you find you need to do.
Wonko the Sane