WPF Setting Custom Colors as XAML Static Resources


Are you working on a project that uses custom colors, perhaps corporate colors? Have you been given the Red Green Blue numbers for a set of these colors? Perhaps you’ve been given the hexadecimal numbers.

When working with XAML in designing the front-end GUI, you want to use your “corporate” or “custom” colors easily.

You can set a static resource. We’ve used the ARGB hexadecimal format. The first two digits, 33, is 51 and that is the optional Apha channel. Red is 0, Green is 88 in hex and Blue is CC in hex.

<Window.Resources>
        <SolidColorBrush x:Key="corporatecolorBrush">#330088CC</SolidColorBrush>
</Window.Resources>

To use the corporatecolorBrush.

<Rectangle Width="80" Height="80" Margin="10">
    <Rectangle.Fill>
        <StaticResource ResourceKey="corporatecolorBrush"/>
    </Rectangle.Fill>
</Rectangle>

For a more advanced example please go to the post called WPF Linear Gradient Brushes.