1

我正在尝试使用渐变在实心块中绘制透明线:

<Grid>
    <Border Margin="-102,-27,102,27">
        <Border.Background>
            <LinearGradientBrush EndPoint="517,160" StartPoint="0,160" MappingMode="Absolute">
                <GradientStop Color="#FF2DBCF2" Offset="0"/>
                <GradientStop Color="#FF2DBCF2" Offset="1"/>
                <GradientStop Color="#002DBCF2" Offset="0.0091" />
                <GradientStop Color="#FF2DBCF2" Offset="0.009"/>
                <GradientStop Color="#002DBCF2" Offset="0.015"/>

                <GradientStop Color="#FF2DBCF2" Offset="0.0151"/>

            </LinearGradientBrush>
        </Border.Background>
    </Border>
</Grid>

问题是,在纯色块的缝隙边缘有一种微弱的褪色效果,使边缘略显不清晰。有没有办法摆脱这种微弱的褪色?我似乎无法找到解决方法。

渐变放大

4

2 回答 2

2

您可以使用以下内容DrawingBrush作为背景:

<Border Margin="-102,-27,102,27">
    <Border.Background>
        <DrawingBrush>
            <DrawingBrush.Drawing>
                <GeometryDrawing Brush="#FF2DBCF2">
                    <GeometryDrawing.Geometry>
                        <GeometryGroup>
                            <RectangleGeometry Rect="0,0,0.01,1"/>
                            <RectangleGeometry Rect="0.015,0,0.985,1"/>
                        </GeometryGroup>
                    </GeometryDrawing.Geometry>
                </GeometryDrawing>
            </DrawingBrush.Drawing>
        </DrawingBrush>
    </Border.Background>
</Border>
于 2013-08-01T12:17:51.803 回答
1

在背景中获得清晰线条的唯一方法是使用ImageBrushorDrawingBrush作为背景而不是LinearGradientBrush

我现在无法制定一个完整的示例,但这应该让您开始了解如何实现 aDrawingBrush作为背景。

<Border.Background>
    <DrawingBrush TileMode="Tile" Stretch="None" Viewport="0,0,20,20" ViewportUnits="Absolute">
        <DrawingBrush.Drawing>
            <GeometryDrawing>
                <GeometryDrawing.Pen>
                    <Pen Brush="White"/>
                </GeometryDrawing.Pen>
                <GeometryDrawing.Geometry>
                    <LineGeometry StartPoint="0.3,0"
                                  EndPoint="0.3,20"/>
                </GeometryDrawing.Geometry>
            </GeometryDrawing>
        </DrawingBrush.Drawing>
    </DrawingBrush>
<Border.Background>
于 2013-08-01T12:13:26.630 回答