如何在 XAML 中定义和使用变量来定义颜色? [英] How can I define and use a variable in XAML to define a color?
本文介绍了如何在 XAML 中定义和使用变量来定义颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的 XAML 中有许多元素将 Foreground="#555" 定义为只读文本框中褪色文本的颜色.
I have a number of elements in my XAML which define Foreground="#555" to be the color of faded text in a readonly textbox.
<TextBlock Text="{Binding SingularModelClassFileTitle}" Margin="0 10 0 0"/>
<TextBox Text="{Binding SingularModelClassFileName}"
HorizontalAlignment="Left"
IsReadOnly="True"
Foreground="#555"
Width="500"/>
<TextBox
VerticalScrollBarVisibility="Visible"
AcceptsReturn="True"
Width="500"
Height="100"
IsReadOnly="True"
Foreground="#555"
Text="{Binding SingularModelClassContent}"
HorizontalAlignment="Left"
Margin="0 0 0 20"/>
如何将此值放入 XAML 变量并在每个属性中引用它,以便我只需在一个地方更改它?
How can I put this value in a XAML variable and reference in each attribute it so that I only have to change it in one place?
我认为你可以做这样的事情:
<sys:String x:Key="ReadOnlyTextColor">#555</sys:String>
...
<TextBox Foreground="{StaticResource ReadOnlyTextColor}"/>
对此的属性 xmlns:sys=...
引用是什么?
And what would be the property xmlns:sys=...
reference for this?
推荐答案
尝试将您的颜色定义为 SolidColorBrush:
Try defining your color as a SolidColorBrush:
<SolidColorBrush x:Key="ReadOnlyTextBrush" Color="#555555" />
...
<TextBox Foreground="{StaticResource ReadOnlyTextColor}" />
这篇关于如何在 XAML 中定义和使用变量来定义颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文