简体   繁体   English

窗口背景颜色:显得比指定的更暗?

[英]Window background color: appears darker than specified?

I'm trying to play around with colors in WPF and the form's background color. 我正在尝试使用WPF中的颜色和表单的背景颜色。 Without doing ANYTHING ELSE (no code behind, deriving from another class, etc), I create a brand new default Windows Form. 没有做任何事情(没有代码,从另一个类派生等),我创建了一个全新的默认Windows窗体。 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 运行该程序并打开该表单..表单显示在一些其他更深的颜色,如它甚至不尊重XAML

<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" Width="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" ); 另外,如果我尝试使用#4800A8A6的相同背景值并尝试创建画笔并执行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. 颜色代码的第一个字节,'48'是一个alpha值,所以你允许在你的Window上进行alpha混合(不是“Windows Form”btw,这是一种不同的技术;)),这意味着你的颜色窗口将与其背后的东西的颜色混合。

Try changing to: #FF00A8A6 , see if that gives you a better result. 尝试更改为: #FF00A8A6 ,看看是否能提供更好的结果。

Your problem is the inclusion of an Alpha channel in the background color (ie #AARRGGBB ). 您的问题是在背景颜色中包含Alpha通道 (即#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. 在设计师中,你看到的背景是针对VS中的背景颜色(在我的情况下为白色)中进行合成,与单独运行时相比,它会“减轻”背景。

To see this for yourself, try Background="#00A8A6" , or you could try adding AllowsTransparency="True" (but this has an onerous requirement of WindowStyle.None ). 要自己查看,请尝试Background="#00A8A6" ,或者您可以尝试添加AllowsTransparency="True" (但这有一个繁琐的WindowStyle.None要求 )。

That's probably because of the alpha component in your color. 这可能是因为你的颜色中的alpha分量。 If you are trying to make your windows transparent, you have to use AllowsTransparency="True" . 如果您尝试使窗口透明,则必须使用AllowsTransparency="True" If you don't, WPF will merge the default windows background color with your windows background. 如果不这样做,WPF会将默认的窗口背景颜色与您的Windows背景合并。

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

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