0

我想要一个填充有棋盘的矩形,它被 LinearGradientBrush 覆盖。只有 GradientBrush 或只有 Checkerboard-DrawingBrush 没有问题。但是如何在 Fill-Property 中覆盖两者?我不能将 Gradient 放在 DrawingGroup 中,因为 Gradient 也会平铺。

这是棋盘画笔:

<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>
4

1 回答 1

2

我会这样做:

<Grid>
    <Rectangle … checkerboard
    <Rectangle … gradient
</Grid>
于 2012-08-31T13:59:31.617 回答