Disabling Listbox does not change background color in style

I have this simple style that does not change the ListBox Background when the ListBox 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 with this, and I cannot figure out an easy way without redefining the templates. Does anyone have an easy way to make this work? TIA.

+4
source share
2 answers

The only way to do this is to override the template.

+2
source

You can change the background color of the list itself when the list is locked, simply by changing the colors used by the built-in template. You can do this through style resources. Just paste the code below into your Listbox element and the background will be transparent when you disable this field.

 <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 often required to change the background color of one element when it is highlighted and when the field loses focus. To change them, you can refer to this post: fooobar.com/questions/1394032 / ...

0
source

Source: https://habr.com/ru/post/1394030/


All Articles