TextBlock brush giving incorrect color
Asked Answered
I

1

6

I have a TextBlock and a Rectangle, both sitting in an empty WPF4 window. The TextBlock's Foreground and the Rectangle's Fill are both set to a SolidColorBrush with value #80800000.

This is what it looks like:

enter image description here

The Rectangle's color is correct (a 50% transparent maroon) but the TextBlock gives a flat grey. What's going on?

EDIT: Here's the XAML:

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <TextBlock Foreground="#80800000" Height="100" HorizontalAlignment="Left" Margin="47,39,0,0" Text="TextBlock" VerticalAlignment="Top" Width="266" FontFamily="Arial" FontWeight="Bold" FontSize="56" />
        <Rectangle Fill="#80800000" Height="100" HorizontalAlignment="Left" Margin="71,174,0,0" Stroke="{x:Null}" VerticalAlignment="Top" Width="200" />
    </Grid>
</Window>
Integrand answered 7/7, 2011 at 3:38 Comment(5)
Thanks for posting the picture. Could you please edit this question to include the XAML as well?Archdiocese
interesting indeed, it seems like same opacity values have different effect on visuals, experimentally you ned to set opacity about 0.7 for textblock to have the same color with rectangleMaleficence
@AndrewShepherd Added the XAML. Not much to it, really.Integrand
I copied and pasted your code into visual studio. The interesting thing is that the color of the text block changes as I zoom in and out with the mouse wheel. When I zoom out (making it small) the text block goes grey. When I zoom in, it goes red to the point where it matches the color of the block.Archdiocese
@AndrewShepherd Yep, I'm seeing that too. When it gets to 200% the correct color shows up.Integrand
K
0

Has this something to do with any of the additional icons you have at the top of your window? This code as expected for me.

screenshot

or are there any additional opacity setting in your code behind?

Kazukokb answered 7/7, 2011 at 4:32 Comment(1)
This is very strange, I compiled & ran the same project on a different machine (HP Elitebook 2760p) and it worked correctly (looked like your screenshot). But the TextBlock still shows up as grey on my desktop workstation. When I set "AllowsTransparency" to True and "WindowStyle" to None on my Window, the TextBlock shows up with the correct color on both machines.Integrand

© 2022 - 2024 — McMap. All rights reserved.