Change the original blocked list to gray

I have a ListBox that I need to disable when it is disabled. At the user's request, this is not enough to turn it off, but it should also look different. shrugs. I looked in several other places and followed examples, and it seems that it should work, but it is not. Here are a few examples that I looked at: Example1 , Example2 .

Here is my code:

 <Style x:Key="ListBoxStyle" TargetType="ListBox"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ListBox}"> <ControlTemplate.Triggers> <Trigger Property="IsEnabled" Value="False"> <Setter Property="BorderBrush" Value="Black"></Setter> <Setter Property="Foreground" Value="LightGray"></Setter> <Setter Property="Background" Value="LightGray"></Setter> <Setter Property="BorderBrush" Value="LightGray"></Setter> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> 

It looks pretty simple. I have successfully completed the same basic process on ComboBox and TextBox . Can someone help me see where my code is wrong? An example of how to do it right will be great. The first example above seemed to be exactly what I needed, but the correct answer: β€œThe only way to do this is to override the template”, which does not help me.

I have already tried some simple solutions. Perhaps some other style may influence this, because we work with several different Resource Dictionaries. Does anyone know what could be a good way to keep track of this?

Edit: I searched the entire solution, and the only place the ListBox is used is my part, and the only place it was written in is the styles that I set. According to MSDN , there are no "parts" of the ListBox, so this is not possible. I inadvertently styled part of the ListBox in the process style for another control. Without styling, when I turn off the ListBox, it is frozen, but visible without text and has a default background. When I try to apply Property = "Background" Value = "LightGray", it seems hidden (i.e. Nothing is visible). If anyone knows why he can do this or how to complete my task, I would appreciate help.

+4
source share
2 answers

I don't think you need to override the ControlTemplate by simply adding that Style.Trigger works fine for me.

Example:

  <ListBox> <ListBox.Style> <Style TargetType="{x:Type ListBox}"> <Style.Triggers> <Trigger Property="IsEnabled" Value="False"> <Setter Property="Foreground" Value="LightGray" /> <Setter Property="Background" Value="LightGray" /> </Trigger> </Style.Triggers> </Style> </ListBox.Style> </ListBox> 
+2
source

sa_ddam213 the answer did not work for me, so I thought that I would add what I found, what I had to do. In my case, I set a transparent background, but when I turn off the window, it will turn gray. I wanted to be able to control the background of the list when the control is disabled, and this is what I found to work.

Note. For your case, you want to change the transparent color to any shade of gray that you want.
note2: This will most likely work only if you have not changed the template for the list. (changing the data table in order).

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

All Articles