简体   繁体   English

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

[英]WPF line color is darker than its brush color

In my WPF application, I am using a line and some rectangles to make a graph. 在我的WPF应用程序中,我使用一行和一些矩形来制作图表。 However, when I set the line to white, it appeared grey. 但是,当我将线条设置为白色时,它显示为灰色。 I changed the line color to be the same as the red rectangle next to it and it is obvious that the line is darker. 我将线条颜色更改为与其旁边的红色矩形相同,很明显线条较暗。 Here is my instantiation of the line and rectangle: 这是我对直线和矩形的实例化:

<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" />

Also, here is a picture of the components: 另外,这是组件的图片: 在此输入图像描述

Nevermind the hardcoding, I am just getting a feel for the layout. 没关系硬编码,我只是感觉布局。

File with the definition of brush resources: 具有画笔资源定义的文件:

<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}" />

With the help of Clemens in the comments, I have discovered that as the line thickness approaches 2, the color value approaches the true color. 在评论中克莱门斯的帮助下,我发现当线条厚度接近2时,颜色值接近真实颜色。 While I still don't know why and would be open to learning, a temporary fix is to set the thickness to 1.99 so that the color appears the same. 虽然我仍然不知道为什么并且愿意学习,但临时修复是将厚度设置为1.99以使颜色看起来相同。 While the thickness is essentially 2, it still has the same visual appearance as 1. 虽然厚度基本上为2,但它仍然具有与1相同的视觉外观。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM