Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Standard view
Full view
of .
Save to My Library
Look up keyword
Like this
0 of .
Results for:
No results containing your search query
P. 1
WPF LinearGradientBrush

WPF LinearGradientBrush

Ratings: (0)|Views: 2 |Likes:
Published by Abhi

More info:

Published by: Abhi on Mar 12, 2012
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less





WPF LinearGradientBrush
A linear gradient brush paints an area with a linear gradient. The LinearGradientBrush objectrepresents a linear gradient brush. The default value linear gradient value is diagonal. TheStartPoint and EndPoint properties of the LinearGradientBrush represent the start and end points of a gradient. The default values of these properties is (0,0) and (1,1), which is upper-left corner tolower-right corner of an area.Figure 16 and 17 show a diagonal gradient (MSDN sample).
 Figure 16. Linear Gradient  Figure 17. Linear Gradient with Stops
Creating a Linear Gradient Brush
The LinearGradientBrush element in XAML creates a linear gradient brush. The following codesnippet creates a linear gradient brush with blue and red colors by setting GradientStops. TheStartPoint and EndPoint values are (0,0) and (1,1).
<LinearGradientBrushStartPoint="0,0"EndPoint="1,1" >  <GradientStopColor="Blue"Offset="0" />  <GradientStopColor="Red"Offset="1.0" />  </LinearGradientBrush>
We can fill a shape with a gradient brush by setting a shape's Fill property to the gradient brush.The code snippet in Listing 15 creates a rectangle shape sets the Fill property to aLinearGradientBrush with blue and red colors.
<RectangleWidth="200"Height="100">  <Rectangle.Fill>  <LinearGradientBrushStartPoint="0,0"EndPoint="1,1" > <GradientStopColor="Blue"Offset="0" />  <GradientStopColor="Red"Offset="1.0" />  </LinearGradientBrush> </Rectangle.Fill> </Rectangle>
 Listing 15
The output looks like Figure 18.
 Figure 18. A shape filled with a linear gradient brush
 Now let's apply multiple stops with multiple colors. The code snippet in Listing 16 creates a linear gradient brush with five stops.
<RectangleWidth="200"Height="100">  <Rectangle.Fill>  <LinearGradientBrushStartPoint="0,0"EndPoint="1,1" > <GradientStopColor="Blue"Offset="0.1" />  <GradientStopColor="Orange"Offset="0.25" />  <GradientStopColor="Yellow"Offset="0.50" />  <GradientStopColor="Green"Offset="0.75" />  <GradientStopColor="Red"Offset="1.0" />  </LinearGradientBrush> </Rectangle.Fill> </Rectangle>
 Listing 16 
The new output generated by Listing 16 looks like Figure 19.
 Figure 19. A linear gradient brush with 5 stops
method listed in Listing 17 draws same rectangle in Figure19 dynamically.
public voidCreateARectangleWithLGBrush() { // Create a Rectangle

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->