#338 – Setting a Control’s Foreground Color

We saw how to set the background of a control to a solid color by specifying a color value for the Background property.  Similarly, you can set the foreground color of a control using the Foreground property.  For controls that contain text, the foreground color is generally the color of the text.

Since the Foreground property’s type is System.Windows.Media.Brush, the property is set to an instance of a Brush object.  In XAML, you can set the property using the name of a predefined color, which maps to a predefined SolidColorBrush in the Brushes class.

        <Button Content="Take a Trip" Foreground="DarkViolet" Width="100" Margin="10"/>

Below is an image showing how some of the more common controls look when the Foreground property is set to a solid color.


About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

One Response to #338 – Setting a Control’s Foreground Color

  1. 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 )

Facebook photo

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

Connecting to %s

%d bloggers like this: