简体   繁体   中英

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. 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. 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. While the thickness is essentially 2, it still has the same visual appearance as 1.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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