#220 – Using the Predefined Colors

The Colors class, in the System.Windows.Media namespace, includes a large set of static properties representing a set of predefined colors.  Each property has a name representing the color, e.g. “Blue”, and is stored internally as a standard WPF Color structure.

The example below shows two different ways of using the predefined colors.  You can use a color name in XAML wherever either a color or a brush is expected.  The name of the color in XAML is converted to a Color value by mapping the name of the color to one of the properties in the Colors class.

        <Button Content="Hello" Background="Purple" />
		<Button Content="Again">
			<Button.Background>
				<SolidColorBrush Color="Blue"/>
			</Button.Background>
		</Button>

Below is an image showing the full list of predefined colors.  (Click on the image to see it full size).

About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

2 Responses to #220 – Using the Predefined Colors

  1. Pingback: #809 – You Can Use a Brush for a Control’s Background | 2,000 Things You Should Know About WPF

  2. Pingback: #810 – Setting Foreground and Background Properties from Code | 2,000 Things You Should Know About WPF

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: