LinearGradientBrush

<Grid Name="grdRoot">
        <Button Name="btnClick" Content="Click" Width="72" Height="24"  />

        <!--LinearGradientBrush只需要注意几个属性:
        1.SpreadMethod:指用什么样的方式去处理不在线性渐变中的区域(即扩展方式,用个比喻吧, 把下面浅绿色的比作一张桌面背景图,把整个区域比作桌面,
SpreadMethod 指定的就是【 平铺 / 拉伸】
        2.MappingMode:指定下面这些属性中StartPoint / EndPoint 输入的值的模式 ,如果是Absolute那么表示是用绝对的方式,如果RelativeToBoundingBox那么就会把canvas影射到一下1*1的矩形框中 ,默认为RelativeToBoundingBox(这在不知道画布的具体长宽时非常有用)
        3.StartPoint: 渐变线的起点, EndPoint 渐变线的终点.请注意这里用到的是一个虚的1*1矩形框(不一定是正方形)
        -->
        <Rectangle>
            <Rectangle.Fill>
                <LinearGradientBrush StartPoint="0,0" EndPoint="1,1" SpreadMethod="Repeat" MappingMode="RelativeToBoundingBox">
                    <GradientStop Color="Red" Offset="0.4" />
                    <GradientStop Color="Green" Offset="0.6" />
                    <GradientStop Color="Blue" Offset="1" />
                </LinearGradientBrush>
            </Rectangle.Fill>
        </Rectangle>
    </Grid>
原文地址:https://www.cnblogs.com/kelei12399/p/2599540.html