我怎样绘制"软QUOT;在WPF线(presumably使用一个LinearGradientBrush)?WPF、QUOT、LinearGradientBrush、presumably

由网友(堇色暮年、笑看这繁华世间)分享简介:我想绘制软边一条线,不管坡。 I'm trying to draw a line with soft edges, regardless of the slope. 这里的code我到目前为止有:Here's the code I have so far: 我想绘制软边一条线,不管坡。

I'm trying to draw a line with soft edges, regardless of the slope.

这里的code我到目前为止有:

Here's the code I have so far:

<Line   HorizontalAlignment="Stretch" VerticalAlignment="Center"
        Stretch="Uniform" StrokeThickness="5" X1="0" Y1="0" X2="1" Y2="0">
    <Shape.Stroke>
        <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
            <GradientStop Color="Transparent" Offset="0" />
            <GradientStop Color="Green" Offset="0.5" />
            <GradientStop Color="Transparent" Offset="1" />
        </LinearGradientBrush>
    </Shape.Stroke>
</Line>

这是有意义的我的,因为行是水平的,并且线性梯度是垂直的,与边缘是透明的,线的中间为绿色。

This makes sense to me, since the line is horizontal, and the linear gradient is vertical, with the edges being transparent and the middle of the line being solid green.

其结果是令人高兴: 放大,所以你可以看到渐变:

The result is pleasing: Zoomed in so you can see the gradient:

然而,当线不再水平,梯度是根据线的边界矩形来计算的,而不是就行本身的几何形状。其结果是,代替梯度垂直于行被竖直阴影斜线,:

However, when the line is no longer horizontal, the gradient is calculated based on the line's bounding rectangle, rather than on the geometry of the line itself. The result is a slanted line that is shaded vertically, instead of the gradient being perpendicular to the line:

有谁知道WPF如何处理软边?我找不到对谷歌或MSDN什么,我知道有一种方法可以做到这一点somewhow ...

Does anyone know how WPF handles soft edges? I can't find anything on Google or MSDN, and I know there is a way to do this somewhow...

推荐答案

好了,我不知道这是否适用于您的情况,但你可以简单地旋转水平线使用LayoutTransform和梯度都会好起来的。

Well, I do not know if that is applicable to your scenario but you could simply rotate the horizontal line using LayoutTransform and the gradient will be okay.

<Line   HorizontalAlignment="Stretch" VerticalAlignment="Center"
    Stretch="Uniform" StrokeThickness="5" X1="0" Y1="0" X2="1" Y2="0">
<Shape.Stroke>
    <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
        <GradientStop Color="Transparent" Offset="0" />
        <GradientStop Color="Green" Offset="0.5" />
        <GradientStop Color="Transparent" Offset="1" />
    </LinearGradientBrush>
</Shape.Stroke>
    <Line.LayoutTransform>
        <RotateTransform Angle="40"/>
    </Line.LayoutTransform>

阅读全文

相关推荐

最新文章