如何使WPF形状完全填充

时间:2012-03-09 01:47:09

标签: wpf silverlight

我有这样的道路,

<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的图形。把两个放在彼此的顶部,他们取消了。

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

2 个答案:

答案 0 :(得分:2)

在查看您的路径并使用PathGeometry.FillRule属性时,我得到两个选项的相同结果。

这是使用Nonzero FilRule和Path

我能够获得你正在寻找的结果的唯一方法是使用Nonzero FillRule并为问题PathFigure创建一个单独的路径。

这是针对问题Path使用非零FillRule和单独的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>

答案 1 :(得分:0)

在PathGeometry元素上尝试设置

FillRule="NonZero"

EvenOdd的默认值给出了您正在描述的XOR行为。