8

I have a TextBox that is defined through a ControlTemplate. Because of the ControlTemplate, the TextBox is no more automatically grayed out when the IsEnabled-property is set to false.

To provide this functionality, I use the following trigger within the ControlTemplate:

<Trigger Property="IsEnabled" Value="False">                            
    <Setter Property="Foreground" Value="{x:Static SystemColors.GrayTextBrush}" />
</Trigger>

This works fine. However I have to set also the BackgroundColor but I don't have found a corresponding entry in SystemColors. Which entry is the right entry for the background of disabled controls (TextBoxes)? Is there another source than SystemColors?

I don't want to use a fixed value. e.g. setting Background="#f4f4f4", because I fear that in some environments, the disabled-background has another value and then my control looks not as it should or even is unreadable (if for example the value of the GrayTextBrush is near #f4).

HCL
  • 36,053
  • 27
  • 163
  • 213

2 Answers2

17

The following StackOverflow question may help:

Visual guide to System.Windows.SystemColors

Edit:

I did some additional sleuthing and looked at the standard XAML styles that Microsoft provides (see Where can I download Microsoft's standard WPF themes from?). You can see exactly which SystemColors values are used for various controls.

For example, here is a snippet of the control template for ComboBox:

<Trigger Property="IsEnabled" Value="false">
    ...
    <Setter
        TargetName="Bd"
        Property="Background"
        Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
    ...
</Trigger>

Microsoft uses SystemColors.ControlBrushKey as the background color of a disabled ComboBox.

Community
  • 1
  • 1
sourcenouveau
  • 29,356
  • 35
  • 146
  • 243
  • +1 Thanks. Interesting post, however the answer to my question I have no found. Have I missed someting? – HCL Nov 16 '10 at 16:37
  • Instead of using a fixed value for your background, you want to use a SystemColors value, correct? By looking at the default XAML styles, it appears that Microsoft uses the SystemColors.ControlBrushKey value as the background color for controls which are disabled. This color should contrast with SystemColors.GrayTextBrush, so the user will be able to read the value when the control is disabled. – sourcenouveau Nov 16 '10 at 16:57
  • 2
    +1 for a great answer. Notice the use of DynamicResource so that the application automatically changes the color if the user changes the color in the Windows theme, while the application is running. – René Dec 13 '12 at 11:29
0

The hex value for Win7 aero SystemColors.ControlBrushKey is F0F0F0. Not F4F4F4. So that one is not correct, don't know which to use so I'm gonna use F4F4F4.

Christian80
  • 449
  • 1
  • 6
  • 17