Working with Brushes WPF: Part 3 in VB.NET
In this article you learn about the all types of brushes and how to working with them in WPF.
Brushes
As you learn in my previous article part 1, part 2 a brush is used to describe the background of a button, the foreground of text, and the fill of a shape and all brushes classes are inherit from System.Windows.Media.Brush and give you more exotic effects.
Here we discuss about the third Brush class that is RadialGradientBrush.
RadialGradientBrush
The RadialGradientBrush works similarly to the LinearGradientBrush. It also takes a sequence of colors with different offsets. As with the LinearGradientBrush, you can use as many colors as you want. The difference is how you place the gradient. The RadialGradientBrush
class provides a way to fill a shape with a circular radial color gradient pattern. The user may specify 2 or more gradient colors, and this paint will provide an interpolation between each color.
Example of an RadialGradientBrush
Xaml Code
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Rectangle Width="80" Height="80">
<Rectangle.Fill>
<RadialGradientBrush GradientOrigin="0.100,0.50">
<GradientStop Color="Blue" Offset="1.1" />
<GradientStop Color="Orange" Offset="0" />
<GradientStop Color="Red" Offset="0.1" />
</RadialGradientBrush>
</Rectangle.Fill>
</Rectangle>
</Window>
VB Code
Dim Rectangle2 As New Rectangle()
Rectangle2.Width = 80
Rectangle2.Height = 80
' Create a RadialGradientBrush and use it to
' paint the rectangle.
Dim Brush As New RadialGradientBrush()
Brush.GradientOrigin = New Point(0.100, 0.50)
Brush.GradientStops.Add(New GradientStop(Colors.blue, 1.1))
Brush.GradientStops.Add(New GradientStop(Colors.Orange, 0))
Brush.GradientStops.Add(New GradientStop(Colors.Red, 0.1))
Rectangle2.Fill = Brush
Output Window
Conclusion
Hope this article will help you understand the working of RadialGradientBrush in WPF. Remaining types of brushes will explain in my next articles.