Friday, August 14, 2009

How to set WPF ListView selected item background color

After my last post I came across another common WPF task that could result in excruciating frustration if you're not using Expression Blend (or you just don't know enough about this shit nice framework): setting the color of the selected item in a ListView.

This is how you do it:

<Style TargetType="{x:Type ListView}">
<Setter Property="BorderBrush" Value="Black"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Margin" Value="0"/>
<!-- here we go -->
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Black"/>
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Gray"/>
<!-- other stuff -->

Hope it helps - if so you can express your gratitude by randomly upvoting some of my answers on stackoverflow.


Anonymous said...

Thanks, this really helped :D

der_Tankwart said...

Cool Blog!

but:Perhaps, there is a failure in your code:

is the "gt" not false?

Barrakoda said...

If you combine this with, the result does not work on Windows 7/Aero.

Barrakoda said...

If you combine this example with the result does not work with Windows 7/Aero.