How to change listbox, combobox or listview selection and background color

This is, probably, one of most common questions about styling in WPF – how to change selected item background color in ListBox (ComboBox, ListView etc). The answer is really simple – look into default control templates of those controls. Those templates using system brushed in order to paint background colors. So, if you want to customize an appearance of those controls, you always can rewrite templates, but why to do it if the only thing you want is to change color brush of elements, so KISS [keep it stupid simple] rewrite those system brushed like this:

      <ComboBox Background=Red>

        <ComboBox.Resources>

          <SolidColorBrush x:Key={x:Static SystemColors.HighlightBrushKey} Color=Yellow />

          <SolidColorBrush x:Key={x:Static SystemColors.ControlBrushKey} Color=Green />

          <SolidColorBrush x:Key={x:Static SystemColors.WindowBrushKey} Color=Red />

        </ComboBox.Resources>

        <TextBlock>TEST</TextBlock>

        <TextBlock>TEST</TextBlock>

        <TextBlock>TEST</TextBlock>

        <TextBlock>TEST</TextBlock>

        <TextBlock>TEST</TextBlock>

        <TextBlock>TEST</TextBlock>

        <TextBlock>TEST</TextBlock>

      </ComboBox>

That’s all, folks. Now you have you own colored combo, that looks like this:

4 Responses to “How to change listbox, combobox or listview selection and background color”

  1. Boris Says:

    Priceless for TreeView

  2. sasan Says:

    thanks for helping me

  3. Carlos Says:

    Very clever approach, tank you

  4. Kelly Luck Says:

    Yes, thank you!  Been beating my head against it a couple days now.  You mentioned examining the default control templates; are those in the new SDK downloads or somewhere like that?  I’d definitely like to know where those are as I try to learn this stuff.

Leave a Reply

Recommended

 


Sponsor


Partners

WPF Disciples
Dreamhost
Code Project
Switched to Better Place

Together