weird issue when drawing a forth and back path in

2019-06-14 09:27发布

问题:

I was drawing a series of points with Path in c# code. I just give an example in xaml.

So the polyline is from (20,37) to (20,36) and returns to (20,37). It is supposed to be very short, right? But it turns to be a segment roughly 9dp long.

if I simply draw from (20,37) to (20,36), it behaves normal. Because the points are drawn in real-time that I cannot do preprocessing.

Why is that and how to solve it?

<Path Stroke="Black" StrokeThickness="2">
    <Path.Data>
        <PathGeometry>
            <PathFigure StartPoint="20,37">
                <PathFigure.Segments>
                    <LineSegment Point="20,36"/>
                    <LineSegment Point="20,37"/>
                </PathFigure.Segments>
            </PathFigure>
        </PathGeometry>
    </Path.Data>
</Path>

回答1:

change StrokeMiterLimit of Path (default is 10)

<Path Stroke="Black" StrokeThickness="2" StrokeMiterLimit="1">