Quantcast
Channel: 2,000 Things You Should Know About WPF » Foreground
Viewing all articles
Browse latest Browse all 3

#811 – Setting Color Values in Code Based on System Colors

$
0
0

You can set the Foreground or Background properties of a control to a brush that will render the control using one of the predefined system colors.  The SystemColors class contains a number of static SolidColorBrush objects representing brushes that match the system colors.

811-001

        <Label Name="lblMA" Content="Margaret Atwood" HorizontalAlignment="Center"
               Padding="20,10" Margin="10"
               Background="LightPink"/>
        <Button Content="Change Color" HorizontalAlignment="Center"
                Padding="10,5" Click="Button_Click"/>

 

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            // Set to one of the predefined brushes that map
            // to the system colors
            lblMA.Background = SystemColors.ActiveCaptionBrush;
        }

811-002
811-003


Filed under: Controls Tagged: Background, Colors, Controls, Foreground, System Colors, WPF

Viewing all articles
Browse latest Browse all 3

Trending Articles