我有一个通过ControlTemplate定义的TextBox.由于ControlTemplate,当IsEnabled-property设置为false时,TextBox不再自动变灰.
为了提供此功能,我在ControlTemplate中使用以下触发器:
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="{x:Static SystemColors.GrayTextBrush}" />
</Trigger>
Run Code Online (Sandbox Code Playgroud)
这很好用.但是我还要设置BackgroundColor但是我没有找到相应的条目SystemColors.哪个条目是禁用控件(TextBoxes)背景的正确条目?是否有另一个源而不是SystemColors?
我不想使用固定值.例如设置Background="#f4f4f4",因为我担心在某些环境中,disabled-background有另一个值,然后我的控件看起来不应该甚至是不可读的(例如,如果GrayTextBrush的值接近#f4).
M. *_*ley 14
以下StackOverflow问题可能有所帮助:
System.Windows.SystemColors的可视指南
编辑:
我做了一些额外的调查,并查看了Microsoft提供的标准XAML样式(请参阅从哪里下载Microsoft的标准WPF主题?).您可以确切地看到哪些SystemColors值用于各种控件.
例如,以下是控件模板的片段ComboBox:
<Trigger Property="IsEnabled" Value="false">
...
<Setter
TargetName="Bd"
Property="Background"
Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
...
</Trigger>
Run Code Online (Sandbox Code Playgroud)
Microsoft将其SystemColors.ControlBrushKey用作禁用的背景颜色ComboBox.
| 归档时间: |
|
| 查看次数: |
9307 次 |
| 最近记录: |