WPF Label Foreground Color
Asked Answered
A

2

31

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

<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?

Alenaalene answered 4/2, 2013 at 13:25 Comment(0)
S
29

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

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.Resources for instance) which might be affecting the labels...

Starch answered 4/2, 2013 at 13:41 Comment(3)
Your guess was right. I noticed this behavior since we added the Metro Styles. Didn't think of that.Alenaalene
Just because I searched how to change the color of a label and it brought me here, I'd like to add that if you simply want to change the color of a label in your code file, this should do: lblStatus.Foreground = new SolidColorBrush(Colors.Red);Rajasthan
or with a bit less code, lblStatus.Foreground = Brushes.Red;Subclimax
S
7

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:

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

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

Savaii answered 7/11, 2019 at 0:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.