Brushes in WPF using VB.NET: Part 1

In this article you learn about the all types of brushes and how to working with them in WPF.
  • 2098

Brushes: A brush is used to describe the background of a button, the foreground of text, and the fill of a shape. The fundamental facts about the brushes are:

  1. Brushes support change notification because they derive from Freezable. As a result, if
    you change a brush, any elements that use that brush repaint themselves automatically.
     

  2. Brushes support partial transparency. All you need to do is modify the Opacity property
    to let the background show through.
     

  3. The SystemBrushes class provides access to brushes that use the colors defined in the
    Windows system preferences for the current computer.

Different brushes have different types of output, Some brushes paint an area with a solid color, others with a gradient, pattern, image, or drawing. The following illustration shows examples of each of the different Brush types.

All brushes classes are inherit from System.Windows.Media.Brush and give you more exotic effects. All brushes classes are:

  • SolidColorBrush

  • LinearGradientBrush

  • RadialGradientBrush

  • ImageBrush

  • DrawingBrush

  • VisualBrush

SolidColorBrush: A SolidColorBrush paints an area with a solid Color. There are a variety of ways to specify the Color of a SolidColorBrush. For example I will through a window that have colored background "Blue".

Example of an SolidColorBrush

<Window x:Class="Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <Canvas Name="cnvPaint" Height="650" Width="650">
        <Canvas.Background>
            <SolidColorBrush Color="Blue"/>
        </Canvas.Background>
    </Canvas>
</
Window>

Output Window

solidbrush.gif
 

Conclusion

Hope this article will help you understand the working of SolidColorBrush in WPF. Remaining types of brushes will explain in my next articles. 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.