开发者

Window background color: appears darker than specified?

开发者 https://www.devze.com 2023-04-06 15:11 出处:网络
I\'m trying to play around with colors in WPF and the form\'s background color.Without doing ANYTHING ELSE (no code behind, deriving from another class, etc),I create a brand new default Windows Form.

I'm trying to play around with colors in WPF and the form's background color. Without doing ANYTHING ELSE (no code behind, deriving from another class, etc), I create a brand new default Windows Form. I change the background to some light blue color. Save the form. Run the program and open that form.. The form shows up in some other much darker color like it's not even respecting the XAML of

<Window x:Class="MyProjectNamespace.AnotherWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="AnotherWindow" Height="300" W开发者_运维技巧idth="300" Background="#4800A8A6">
    <Grid>

    </Grid>
</Window>

Additionally, if I try to take this same background value of #4800A8A6 and try to create a brush and do a BrushConverter.ConvertFrom( "#4800A8A6" ); and run the form, I STILL get the incorrect color as displayed via the designer... what gives...


The first byte of your color code, the '48' is an alpha value, so you're allowing alpha blending on your Window (not a "Windows Form" btw, that's a different technology ;) ), which means the color of your window is going to be blended with the colors of things behind it.

Try changing to: #FF00A8A6, see if that gives you a better result.


Your problem is the inclusion of an Alpha channel in the background color (i.e. #AARRGGBB). In the designer you're seeing the background being composited against whatever the background color is in VS (in my case White), which will "lighten" the background in comparison to when you run it as standalone.

To see this for yourself, try Background="#00A8A6", or you could try adding AllowsTransparency="True" (but this has an onerous requirement of WindowStyle.None).


That's probably because of the alpha component in your color. If you are trying to make your windows transparent, you have to use AllowsTransparency="True". If you don't, WPF will merge the default windows background color with your windows background.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号