0

Possible Duplicate:
wpf set ComboBox selected item highlight color

First off sorry if this has been answered, I have been browsing Google all evening trying to find a solution and not even sure if what I am searching for is right.

My problem is when I click/hover over a Combobox/button ect it shows the default system blue colour, I want to be able to remove it or change it to the gray I use when hovering over selections in the combo box. This is a WPF project and I have added some pictures to show what the problem is. I have tried several different things with no luck. I am hoping I have overlooked a simple setting.

enter image description here

Community
  • 1
  • 1
  • Confused which do you want to do change the colour of a selected item in a control, when it's being hovered over, or the control when it's being hovered over. Two different animals. – Tony Hopkinson Oct 03 '12 at 12:04
  • @TonyHopkinson knowing the youth its the blue combobox that gets an system color – EaterOfCode Oct 03 '12 at 12:10
  • 1
    is this what you need? http://stackoverflow.com/questions/1278144/wpf-set-combobox-selected-item-highlight-color – Nahum Oct 03 '12 at 12:12

1 Answers1

0

At a high level you need to style your ComboBox.

Here is a good blog post on how to make it look completely different.

To change the default color you need this type of xmal (taken from this blog)

 <ControlTemplate x:Key="CustomToggleButton" TargetType="ToggleButton">
    <Grid>
        <Border Name="Border" />
        <Border Name="SmallBorder" />
        <Path Name="Arrow" />
    </Grid>
</ControlTemplate>

<Style TargetType="{x:Type ComboBoxItem}">
    <Setter Property="FrameworkElement.OverridesDefaultStyle" Value="True" />
    <Setter Property="Control.Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ComboBoxItem}">
                <Border>
                    <ContentPresenter />
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

<Style TargetType="{x:Type ComboBox}">
    <Setter Property="FrameworkElement.OverridesDefaultStyle" Value="True" />
    <Setter Property="Control.Template">
        <Setter.Value>
            <ControlTemplate TargetType="ComboBox">
                <Grid>
                    <ToggleButton Template="{StaticResource CustomToggleButton}" />
                    <ContentPresenter />
                    <TextBox />
                    <Popup>
                        <Grid>
                            <Border>
                                <ScrollViewer>
                                    <ItemsPresenter />
                                </ScrollViewer>
                            </Border>
                        </Grid>
                    </Popup>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
David Basarab
  • 72,212
  • 42
  • 129
  • 156