LinearGradientBrush 使用线性渐变绘制区域。 线性渐变沿直线定义渐变。 该直线的终点由线性渐变的 StartPoint 和 EndPoint 属性定义。LinearGradientBrush 画笔沿此直线绘制其 GradientStops

默认的线性渐变是沿对角方向进行的。 默认情况下,线性渐变的 StartPoint 是被绘制区域的左上角 (0,0),其 EndPoint 是被绘制区域的右下角 (1,1)。 所得渐变的颜色是沿着对角方向路径插入的。

下图演示对角渐变。 其中添加了一条线,用于突出显示渐变从起点到终点的内插路径。

对角方向的线性渐变


对角线方向线性渐变的渐变轴

下一幅插图显示的是同一线性渐变,但它具有突出显示的渐变停止点。

具有突出显示的渐变停止点的对角线性渐变


线性渐变中的渐变停止点

可以指定未完全填充所绘制区域的渐变轴。 出现这种情况时,SpreadMethod 属性确定其余区域的绘制方式。

 

Example:

 1 <Grid>
 2         <Grid.Background>
 3             <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
 4                 <GradientStop Color="Yellow" Offset="0.0" />
 5                 <GradientStop Color="Red" Offset="0.25" />
 6                 <GradientStop Color="Blue" Offset="0.75" />
 7                 <GradientStop Color="LimeGreen" Offset="1.0" />
 8             </LinearGradientBrush>
 9         </Grid.Background>
10         <Button  Content="Button" Height="50" HorizontalAlignment="Left" Margin="76,121,0,0" Name="button1" VerticalAlignment="Top" Width="94" >
11             <Button.Background>
12                 <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
13                     <GradientStop Color="Green" Offset="0.2"></GradientStop>
14                     <GradientStop Color="LightGreen" Offset="0.4"></GradientStop>
15                     <GradientStop Color="Yellow" Offset="0.8"></GradientStop>
16                     <GradientStop Color="LightYellow" Offset="1"></GradientStop>
17                 </LinearGradientBrush>
18             
19             </Button.Background>
20         </Button>
21     </Grid>

参考:LinearGradientBrush 类

posted on 2014-09-08 19:52  homingfly  阅读(1177)  评论(0编辑  收藏  举报