如何在 WPF 中对路径进行分组?

Lil*_*y S 2 wpf geometry-path

我正在使用路径来创建特定的形状。对所有路径进行分组的最佳方法是什么,以便稍后我可以在另一个位置使用它们而无需重新定位路径?

任何建议都会很棒,谢谢!

Cle*_*ens 5

如果问题是关于一个只有一个填充和笔触的复杂形状,一个选项是只使用一个 Path 实例和一个PathGeometry和多个Figures。请参阅 MSDN 中的以下示例:

<Path Stroke="Black" StrokeThickness="1">
    <Path.Data>
        <PathGeometry>
            <PathGeometry.Figures>
                <PathFigureCollection>
                    <PathFigure IsClosed="True" StartPoint="10,100">
                        <PathFigure.Segments>
                            <PathSegmentCollection>
                                <LineSegment Point="100,100" />
                                <LineSegment Point="100,50" />
                            </PathSegmentCollection>
                        </PathFigure.Segments>
                    </PathFigure>
                    <PathFigure IsClosed="True" StartPoint="10,10">
                        <PathFigure.Segments>
                            <PathSegmentCollection>
                                <LineSegment Point="100,10" />
                                <LineSegment Point="100,40" />
                            </PathSegmentCollection>
                        </PathFigure.Segments>
                    </PathFigure>
                </PathFigureCollection>
            </PathGeometry.Figures>
        </PathGeometry>
    </Path.Data>
</Path>
Run Code Online (Sandbox Code Playgroud)