开发者

howto draw a curve with alternating colors in wpf

开发者 https://www.devze.com 2023-02-08 17:22 出处:网络
I need to draw 开发者_如何学Ca curve in WPF on a canvas, which alternates colour, say black and yellow. Kinda like a dashed stroke, but I think dash uses the stroke brush and the fill colour and I nee

I need to draw 开发者_如何学Ca curve in WPF on a canvas, which alternates colour, say black and yellow. Kinda like a dashed stroke, but I think dash uses the stroke brush and the fill colour and I need the fill colour to be transparent (only want the line).

The curve is drawn like this:

<Canvas Width="150" Height="200">
  <Path Data="M 25,45 C 50,12 100,12 125,45" Stroke="Black" />
</Canvas>

Thanks,

Terje


You could use two Paths that have the same data, one with a solid black stroke and one with a dashed yellow stroke. Make sure the dashed yellow Path is in front of the solid black Path, i.e., the dashed yellow Path should be declared below the black one in your XAML.


Here's the WPF the Ben Schoepke was describing.

    <Canvas Width="150" Height="200">
        <Path Data="M 25,45 C 50,12 100,12 125,45" Stroke="Black" />
        <Path Data="M 25,45 C 50,12 100,12 125,45" StrokeDashArray="4" Stroke="Yellow" />
    </Canvas>

Or alternatively

    <Canvas Width="150" Height="200">
        <Path Data="M 25,45 C 50,12 100,12 125,45" Stroke="Yellow" />
        <Path Data="M 25,45 C 50,12 100,12 125,45"  StrokeDashArray="4"  Stroke="Black" />

    </Canvas>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号