5

I have this simple style that does not change the ListBox Background when the ListBox is disabled:

<Style TargetType="ListBox" >                    
    <Style.Triggers>
        <Trigger Property="IsEnabled" Value="True">
            <Setter Property="Background" Value="Red"/>
        </Trigger>
        <Trigger Property="IsEnabled" Value="False">
            <Setter Property="Background" Value="Orange"/>
        </Trigger>
    </Style.Triggers>
</Style>

Snoop does not help me on this one and I cannot figure a simple way without overriding templates. Anyone have a simple way to get this working? TIA.

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Klaus Nji
  • 18,107
  • 29
  • 105
  • 185

2 Answers2

2

The only way to do this is by overriding the template

MyKuLLSKI
  • 5,285
  • 3
  • 20
  • 39
0

You can change the background color of the listbox itself when the listbox is disabled by simply changing the colors that the built-in template is using. You can do this via style resources. Just paste the below code into your Listbox element and the background will be transparent when you disable the box.

<ListBox.Style>
    <Style TargetType="{x:Type ListBox}">
        <Style.Resources>
            <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent"/>
        </Style.Resources>
    </Style>
</ListBox.Style>

It is also very common to want to modify the background color of a single item when it's highlighted and when the box loses focus.. to change these, you can reference this post: https://stackoverflow.com/a/7298301/1721136

Community
  • 1
  • 1
Bill Tarbell
  • 4,933
  • 2
  • 32
  • 52