本文介绍了TextBlock笔刷颜色不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个TextBlock和一个Rectangle,它们都坐在一个空的WPF4窗口中. TextBlock的前景和Rectangle的填充都设置为值#80800000的SolidColorBrush.

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.

这是它的样子:

矩形的颜色是正确的(50%透明的栗色),但是TextBlock给出的是浅灰色.发生了什么事?

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

这是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>

推荐答案

这与您位于窗口顶部的任何其他图标有关系吗?该代码符合我的预期.

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.

屏幕截图

还是您的代码后面还有其他不透明度设置?

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

这篇关于TextBlock笔刷颜色不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 07:04