#811 – Setting Color Values in Code Based on System Colors
May 2, 2013 1 Comment
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.
<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; }