我想要一个用棋盘填充的矩形,上面覆盖着LinearGradientBrush。只有GradientBrush或只有CheckerboardDrawingBrush是没有问题的。但是如何在Fill属性中覆盖两者呢?我不能把渐变放在DrawingGroup中,因为渐变也会平铺。
这是棋盘绘图刷:
<Rectangle.Fill>
<DrawingBrush Viewport="0,0,0.5,0.05" TileMode="Tile">
<DrawingBrush.Drawing>
<DrawingGroup>
<GeometryDrawing Brush="White">
<GeometryDrawing.Geometry>
<RectangleGeometry Rect="0,0,100,100" />
</GeometryDrawing.Geometry>
</GeometryDrawing>
<GeometryDrawing >
<GeometryDrawing.Geometry>
<GeometryGroup>
<RectangleGeometry Rect="0,0,50,50" />
<RectangleGeometry Rect="50,50,50,50" />
</GeometryGroup>
</GeometryDrawing.Geometry>
<GeometryDrawing.Brush >
<LinearGradientBrush>
<GradientStop Offset="0.0" Color="Black" />
<GradientStop Offset="1.0" Color="Gray" />
</LinearGradientBrush>
</GeometryDrawing.Brush>
</GeometryDrawing>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
</Rectangle.Fill>
那么如何在整个矩形上应用渐变呢?
<LinearGradientBrush>
<GradientStop Color="White" Offset="0" />
<GradientStop Color="Transparent" Offset="1" />
</LinearGradientBrush>
我会这样做:
<Grid>
<Rectangle … checkerboard
<Rectangle … gradient
</Grid>