在wpf中绘制双线

Meg*_*ind 2 c# wpf styles line

我需要使用笔划破折号数组或类似的东西在 wpf 中绘制这样的线条。这应该代表单线对象而不是两个平行线对象。

在此处输入图片说明

Joh*_*wen 5

您可以通过LinearGradientBrush为您的Stroke. 像这样的东西:

<Line.Stroke>
    <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
        <LinearGradientBrush.GradientStops>
            <GradientStopCollection>
                <GradientStop Color="Black" Offset="0.2"/>
                <GradientStop Color="Transparent" Offset="0.201"/>
                <GradientStop Color="Transparent" Offset="0.799"/>
                <GradientStop Color="Black" Offset="0.8"/>
            </GradientStopCollection>
        </LinearGradientBrush.GradientStops>
    </LinearGradientBrush>
</Line.Stroke>
Run Code Online (Sandbox Code Playgroud)

您还应该将线条的Height和设置StrokeThickness为相同的值,以确保显示整个渐变。