如何使WPF形状完全填充?

3

我有一个像这样的路径,

<Path Stroke="Black" StrokeThickness="1" Fill="#CCCCFF">
    <Path.Data>
    <PathGeometry>
        <PathFigure StartPoint="6.0,12.5" >
            <LineSegment Point="50.0,6.0"></LineSegment>
            <LineSegment Point="94.0,12.5"></LineSegment>
            <LineSegment Point="60.0,19.0"></LineSegment>
            <LineSegment Point="20.0,19.0"></LineSegment>
            <LineSegment Point="6.0,12.5"></LineSegment>
        </PathFigure>
        <PathFigure StartPoint="7.97852754592896,12.2077178955078">
            <ArcSegment IsLargeArc="True" Point="4.02147245407104,12.7922821044922" RotationAngle="171.59663391113281" Size="2,4" SweepDirection="Counterclockwise"></ArcSegment>
            <ArcSegment IsLargeArc="True" Point="7.97852754592896,12.2077178955078" RotationAngle="171.59663391113281" Size="2,4" SweepDirection="Counterclockwise"></ArcSegment>
        </PathFigure>
        <PathFigure StartPoint="51.9785270690918,6.29228210449219">
            <ArcSegment IsLargeArc="True" Point="48.0214729309082,5.70771789550781" RotationAngle="188.40336608886719" Size="2,4" SweepDirection="Counterclockwise"></ArcSegment>
            <ArcSegment IsLargeArc="True" Point="51.9785270690918,6.29228210449219" RotationAngle="188.40336608886719" Size="2,4" SweepDirection="Counterclockwise"></ArcSegment>
        </PathFigure>
    </PathGeometry>
  </Path.Data>
</Path>

这是一个带有几个圆角的多边形。

其中一个圆没有正确填充。它恰好是覆盖多边形的圆的一部分。

它让我想起使用XOR的图形。将两个放在彼此上方,它们就会相互抵消。

如果我删除多边形(线段),那么它就可以正常工作。

2个回答

2
在查看您的路径并尝试使用PathGeometry.FillRule属性时,我发现两个选项的结果都相同。
这是使用单个Path的非零填充规则。 我唯一能够得到您要找的结果的方法是使用非零FillRule并为问题PathFigures创建一个单独的路径。
这是使用单独的Path和非零填充规则的问题PathFigures
<Path Stroke="Black" StrokeThickness="1" Fill="#CCCCFF">
    <Path.Data>
        <PathGeometry FillRule="Nonzero">
            <PathFigure StartPoint="6.0,12.5" >
                <LineSegment Point="50.0,6.0"></LineSegment>
                <LineSegment Point="94.0,12.5"></LineSegment>
                <LineSegment Point="60.0,19.0"></LineSegment>
                <LineSegment Point="20.0,19.0"></LineSegment>
                <LineSegment Point="6.0,12.5"></LineSegment>
            </PathFigure>
        </PathGeometry>
    </Path.Data>
</Path>
<Path Stroke="Black" StrokeThickness="1" Fill="#CCCCFF">
    <Path.Data >
        <PathGeometry FillRule="Nonzero">
            <PathFigure StartPoint="51.9785270690918,6.29228210449219">
                <ArcSegment IsLargeArc="True" Point="48.0214729309082,5.70771789550781" RotationAngle="188.40336608886719" Size="2,4" SweepDirection="Counterclockwise"></ArcSegment>
                <ArcSegment IsLargeArc="True" Point="51.9785270690918,6.29228210449219" RotationAngle="188.40336608886719" Size="2,4" SweepDirection="Counterclockwise"  ></ArcSegment>
            </PathFigure>
            <PathFigure StartPoint="7.97852754592896,12.2077178955078" >
                <ArcSegment IsLargeArc="True" Point="4.02147245407104,12.7922821044922" RotationAngle="171.59663391113281" Size="2,4" SweepDirection="Counterclockwise"></ArcSegment>
                <ArcSegment IsLargeArc="True" Point="7.97852754592896,12.2077178955078" RotationAngle="171.59663391113281" Size="2,4" SweepDirection="Counterclockwise"></ArcSegment>
            </PathFigure>
        </PathGeometry>
    </Path.Data>
</Path>

好的,这看起来很有前途。我原本认为圆圈不会覆盖多边形的角落。为两个填充值添加较低的 alpha 通道可以实现我想要的效果。这是必需的,因为这些形状正在地图上绘制。这需要通过形状看到背景,以便用户在绘制形状时可以看到道路。 - peter

0
在你的PathGeometry元素上尝试设置:
FillRule="NonZero"

EvenOdd 的默认值会给出你所描述的异或行为。


是的,这确实很奇怪。有人跟我提到过这个问题,看起来似乎是答案,但是没有任何改变。谢谢。 - peter

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接