Search code examples
c#wpfxamlbackgroundbrushes

Window background color: appears darker than specified?


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" 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" ); and run the form, I STILL get the incorrect color as displayed via the designer... what gives...


Solution

  • 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.