#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">
				<SolidColorBrush Color="Blue"/>

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 software development and sailing.

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 )

Connecting to %s

%d bloggers like this: