WPF渐变中的实线透明线

时间:2013-08-01 12:03:04

标签: wpf xaml gradient

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

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

问题在于,在纯色块的间隙边缘处存在微弱的褪色效果,这使得边缘略微不那么脆。有没有办法摆脱这种微弱的褪色?我似乎无法找到解决办法。

Gradient Zoomed in

2 个答案:

答案 0 :(得分: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>

答案 1 :(得分:1)

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

我现在无法找到完整的示例,但这应该让您开始了解如何实现DrawingBrush作为背景。

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