WPF 标签前景色

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14687743/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 23:40:11  来源:igfitidea点击:

WPF Label Foreground Color

wpfcolorsforeground

提问by JuHwon

I have 2 Labels in a StackPaneland set a Foregroundcolor to both of them... The second one shows as black, when it shouldn't.

Label在 a 中有 2 sStackPanelForeground为它们设置了一种颜色......第二个显示为黑色,当它不应该时。

<StackPanel HorizontalAlignment="Right" Orientation="Horizontal"  Grid.Column="4" Grid.Row="0" Width="Auto" Margin="0,0,20,0">
    <Label Content="{lex:LocText CGI, Suffix=:}" Foreground="#FFE0E0E0" FontSize="24" VerticalAlignment="Bottom" Margin="0,0,0,10" HorizontalAlignment="Right" />
    <Label Content="{Binding Cgi}" ContentStringFormat="{}{0}%" Foreground="#FFE0E0E0" FontSize="24" VerticalAlignment="Bottom" Margin="0,0,0,10" HorizontalAlignment="Right" />
</StackPanel>

Is there something I'm doing wrong?

有什么我做错了吗?

采纳答案by Blachshma

I checked your XAML, it works fine - e.g. both labels have a gray foreground.
My guess is that you have some style which is affecting the way it looks...

我检查了您的 XAML,它工作正常 - 例如,两个标签都有灰色前景。
我的猜测是你的一些风格影响了它的外观......

Try moving your XAML to a brand-new window and see for yourself... Then, check if you have any themes or styles (in the Window.Resourcesfor instance) which might be affecting the labels...

尝试将您的 XAML 移动到一个全新的窗口并亲自查看...然后,检查您是否有任何Window.Resources可能影响标签的主题或样式(例如)...

回答by jbobbins

The title "WPF Label Foreground Color" is very simple (exactly what I was looking for) but the OP's code is so cluttered it's easy to miss how simple it can be to set text foreground color on two different labels:

标题“WPF Label Foreground Color”非常简单(正是我要找的),但是 OP 的代码太混乱了,很容易错过在两个不同的标签上设置文本前景色是多么简单:

<StackPanel>
    <Label Foreground="Red">Red text</Label>
    <Label Foreground="Blue">Blue text</Label>
</StackPanel>

In summary, No, there was nothing wrong with your snippet.

总之,不,您的代码段没有任何问题。