Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overriding ListBoxItem background color when not in focus (.NET 4.5)

Tags:

According to this, overriding the ControlBrushKey resource should change the background color of a ListBox selected item when it doesn't have focus. I created a simple example to disprove this:

 <StackPanel>
    <ListBox>
      <ListBox.Resources>
        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="LightBlue"/>
        <!--SelectedItem without focus but doesn't really work-->
        <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Orange" />
      </ListBox.Resources>
      <ListBoxItem>
        Item 1
      </ListBoxItem>
      <ListBoxItem>
        Item 2
      </ListBoxItem>
    </ListBox>
    <TextBox></TextBox>
  </StackPanel>

If you run this in .NET 4.5 you can see that it only changes the in-focus color, but not the not-in-focus (it works in .NET 4.0). Any idea why?

Edit: This seems to be duplicate of List/Combo Box Background And Selected Colours Under .net 4.5.