WPF线条颜色比其笔刷颜色更深

时间:2017-06-22 16:08:28

标签: c# wpf colors line

在我的WPF应用程序中,我使用一行和一些矩形来制作图表。但是,当我将线条设置为白色时,它显示为灰色。我将线条颜色更改为与其旁边的红色矩形相同,很明显线条较暗。这是我对直线和矩形的实例化:

<Line Grid.Row="2" X1="0" Y1="0" X2="0" Y2="105" 
                  StrokeThickness="1" Stroke="{StaticResource FgRedBrush}" SnapsToDevicePixels="True" UseLayoutRounding="True"
                  Margin="10 0 0 10" VerticalAlignment="Bottom" StrokeEndLineCap="Flat" />
            <Rectangle Grid.Row="2" Width="100" Height="30"
                       Fill="{StaticResource FgGreenBrush}"
                       Margin="11 0 0 25" VerticalAlignment="Bottom" HorizontalAlignment="Left" />
            <Rectangle Grid.Row="2" Width="170" Height="30" 
                       Fill="{StaticResource FgRedBrush}"
                       Margin="11 0 0 70" VerticalAlignment="Bottom" HorizontalAlignment="Left" />

此外,这是组件的图片:enter image description here

没关系硬编码,我只是感觉布局。

带有画笔资源定义的文件:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:local="clr-namespace:Financial_Manager.Colors">

<Color x:Key="ForegroundLight">#D7F6F6</Color>
<Color x:Key="ForegroundDark">#898989</Color>
<Color x:Key="ForegroundPurple">#D228FF</Color>
<Color x:Key="ForegroundBlue">#4DC6D2</Color>
<Color x:Key="ForegroundOrange">#F99D10</Color>
<Color x:Key="ForegroundGreen">#37AE53</Color>
<Color x:Key="ForegroundRed">#CE260B</Color>
<Color x:Key="ForegroundYellow">#CCFF00</Color>

<SolidColorBrush x:Key="FgLightBrush" Color="{StaticResource ForegroundLight}" />
<SolidColorBrush x:Key="FgDarkBrush" Color="{StaticResource ForegroundDark}" />
<SolidColorBrush x:Key="FgPurpleBrush" Color="{StaticResource ForegroundPurple}" />
<SolidColorBrush x:Key="FgBlueBrush" Color="{StaticResource ForegroundBlue}" />
<SolidColorBrush x:Key="FgOrangeBrush" Color="{StaticResource ForegroundOrange}" />
<SolidColorBrush x:Key="FgGreenBrush" Color="{StaticResource ForegroundGreen}" />
<SolidColorBrush x:Key="FgRedBrush" Color="{StaticResource ForegroundRed}" />
<SolidColorBrush x:Key="FgYellowBrush" Color="{StaticResource ForegroundYellow}" />

<Color x:Key="BackgroundLight">#0D0A1C</Color>
<Color x:Key="BackgroundDark">#080610</Color>

<SolidColorBrush x:Key="BgLightBrush" Color="{StaticResource BackgroundLight}" />
<SolidColorBrush x:Key="BgDarkBrush" Color="{StaticResource BackgroundDark}" />

1 个答案:

答案 0 :(得分:0)

在评论中借助Clemens,我发现当线条厚度接近2时,颜色值接近真实颜色。虽然我仍然不知道为什么并且愿意学习,但临时修复是将厚度设置为1.99以使颜色出现相同。虽然厚度基本上为2,但它仍具有与1相同的视觉外观。