#338 – Setting a Control’s Foreground Color
July 8, 2011 1 Comment
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.
Pingback: #810 – Setting Foreground and Background Properties from Code | 2,000 Things You Should Know About WPF