在Fill-Property中叠加两个画笔

时间:2012-08-31 13:50:55

标签: c# .net wpf xaml drawingbrush

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

这是Checkerboard-DrawingBrush:

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

1 个答案:

答案 0 :(得分:2)

我会这样做:

<Grid>
    <Rectangle … checkerboard
    <Rectangle … gradient
</Grid>