禁用的文本框的BackgroundColor中 [英] BackgroundColor of a disabled TextBox

查看:126
本文介绍了禁用的文本框的BackgroundColor中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通过控件模板中定义的文本框。由于控件模板中,文本框不再是自动变灰时的IsEnabled-属性设置为false。

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.

要提供这一功能,我使用的ControlTemplate中的以下触发:

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>

这工作得很好。不过,我也必须设置BackgroundColor中,但我没有发现 systemColors中有相应的条目。其中项是禁用的控件(文本框)的背景下进入的权利?是否有比systemColors中其他来源?

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?

我不希望使用一个固定值。例如设置背景=#f4f4f4,因为我担心在某些环境中,残疾人,背景有另一个值,然后我的控制看起来并不像它应该甚至无法读取(如果例如GrayTextBrush的值接近#F4)。

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).

推荐答案

下面的StackOverflow问题可能会有帮助:

The following StackOverflow question may help:

视觉引导System.Windows.SystemColors

编辑:

我做了一些额外的侦探,看着Microsoft提供的标准XAML样式(见<一href="http://stackoverflow.com/questions/4158678/where-can-i-download-microsofts-standard-wpf-themes-from">Where我可以从下载微软的标准WPF主题?)。你可以看到到底是哪个 systemColors中值用于各种控制。

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使用 SystemColors.ControlBrushKey 作为背景色被禁用组合框

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

这篇关于禁用的文本框的BackgroundColor中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆