Working with brushes in WPF

Ratings:
(4)
Views:693
Banner-Img
  • Share this blog:

A brush paints an area with its output. A brush is used to describe the loack ground of a button or foreground of a next or to fill a particular shape - - > Brushes enable us to paint user interface objects with anything from simple so rid colors. As well as complete set of patterns and images

Types of brushes in WPF

  1. Brush
  2. Solid brush
  3. Drawing brush
  4. Gradient brush
  5. Linear gradient brush
  6. Radial gradient brush
  7. Solid color brush
  8. Image brush
  9. Tiled brush
  10. Visual brush

 

Brush

This is a simple brush and is used to change the background or foreground colors of controls - - > This is in general not used with 2D or 3D images  

Common property with all brushes

Color

This is used to set or get the required color to the required object foreground or background  

Solid color brush 

This is used to fill a single color within the graphic object we cannot fill two or more colors using solid color brush within the graphic object  

Eg with solid color brush

  <window> <Grid> <Rectangle width=”100” Horizontal alignment=”Top” Margin= <Rectangle.fill> <solid color Brush color = “eed”/> </rectangle.fill> </rectangles>  

Linear Gradient brush

This is used to fill the colors or apply the colors to a graphic image àUsing liner gradient brush we can fill or apply two or more colors at once within the graphic object - - > Using linear gradient brush we can apply or fill the colors diagonally (or) horizontally (or) vertically This sub tag <Gradient stop> has two attributesàWe use a sub tag known as Gradient stop Within the linear gradient brush class - - > Color - - > offset  

Offset

Property is used to mention a location upto where the color should be applied or filled <Gradient stop color= “blue” offset= “1.4”/>àIf, we want to fill 3 colors in a square then we use linear gradient brush like <Linear Gradient Brush> <Gradient stop color= “Red” Offset = “0.3”/> <Gradient stop color=”green” offset=”0.6”/> </linearGradient brush>   Screenshot_25  

  • Default filling of the colors in linear gradient brush is diagonal
  • If we want to fill the colors horizontally or vertically then we use start pint and end point properties with linear gradient brush
  • To Fill the colors Horizontally  we write

Start point = “0,0.5” End point = “0,1.0” like <Line as gradient brush start point= “0.0.5” End point =”0,1.0”/> <Gradient stop color = “Red” offset = “0.3”/> <Gradient stop color = “Green” offset = “0.6”/> <Gradient stop color = “Blue” Offset = “%.4%> </Linear Gradient brush>   Screenshot_26   Eg With linear Gradient Brush Create a new window Go to source write the following code within the grid <Grid> <Rectangle Height=”100” width=”100”> <Rectangle Fill> <Linear gradient brush> <Gradient stop-color=”red” offset= “0.3”/> <Gradient stop-color=”green” Offset =”0.6”/> <Gradient stop color=”blue” offset =”1.0”/>   Screenshot_27   </Rectangle.fill> <Linear Gradient brush Start point = “0, 0.5” Endpoint = “0,1.0”/> <Gradient stop color = “orange” Offset = “0.3”/> <Gradient stop color= “green” Offset = “1.0”/> </Linear Gradient brush> </rectangle.fill> </Gird>   Screenshot_29 <Ellipse Height = “100” width = “100”> <linear gradient Brush> <Gradient stop  

  • Radial Gradient Brush:- Used to fill the colors within the graphic image circularly
  • Properties of this are same as linear gradient brash, but we don’t find start point and end point

 

Eg with Radial Gradient Brush

Create a new WPF apps

      ↓

Create a new window

      ↓

Go to xaml source

      ↓

Write the following code

      ↓

<Rectangle Height = ‘100”, width =”100”/> <rectangle.file> <Radial Gradient Brush> <Gradientstop color=”Red” offset = “0.3”/> <Gradientstop color=”Green” offset = “0.6”/> <Gradientstop color=”Blue” offset= “1.4”/> </Radial Gradient brush> </Rectangle.fill> </RECTANGLE> Screenshot_30

You liked the article?

Like : 0

Vote for difficulty

Current difficulty (Avg): Medium

Recommended Courses

1/15

About Author
Authorlogo
Name
TekSlate
Author Bio

TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.


Stay Updated


Get stories of change makers and innovators from the startup ecosystem in your inbox