0

我有一个长度为“n”的动态字符串列表,需要画一个圆圈,分成“n”个相等的部分,并将名称分成几部分。

我发现这段 Xaml 代码生成 3 个部分,但我不知道如何以编程方式进行

<Image Width="500" Height="500" Name="image1">
            <Image.Source>
                <DrawingImage>
                    <DrawingImage.Drawing>
                        <DrawingGroup>

                            <GeometryDrawing Brush="Red">
                                <GeometryDrawing.Pen>
                                    <Pen Brush="Black" />
                                </GeometryDrawing.Pen>
                                <GeometryDrawing.Geometry>
                                    <PathGeometry>
                                        <PathFigure StartPoint="100,100">
                                            <PathFigure.Segments>
                                                <LineSegment Point="100,0"/>
                                                <ArcSegment Point="186.6,150"  SweepDirection="Clockwise" Size="100,100"/>
                                                <LineSegment Point="100,100"/>
                                            </PathFigure.Segments>
                                        </PathFigure>
                                    </PathGeometry>
                                </GeometryDrawing.Geometry>
                            </GeometryDrawing>

                            <GeometryDrawing Brush="Blue">
                                <GeometryDrawing.Pen>
                                    <Pen Brush="Black"/>
                                </GeometryDrawing.Pen>
                                <GeometryDrawing.Geometry>
                                    <PathGeometry>
                                        <PathFigure StartPoint="100,100">
                                            <PathFigure.Segments>
                                                <LineSegment Point="186.6,150"/>
                                                <ArcSegment Point="13.4,150" SweepDirection="Clockwise" Size="100,100"/>
                                                <LineSegment Point="100,100"/>
                                            </PathFigure.Segments>
                                        </PathFigure>
                                    </PathGeometry>
                                </GeometryDrawing.Geometry>
                            </GeometryDrawing>

                            <GeometryDrawing Brush="Green">
                                <GeometryDrawing.Pen>
                                    <Pen Brush="Black"/>
                                </GeometryDrawing.Pen>
                                <GeometryDrawing.Geometry>
                                    <PathGeometry>
                                        <PathFigure StartPoint="100,100">
                                            <PathFigure.Segments>
                                                <LineSegment Point="13.4,150"/>
                                                <ArcSegment Point="100,0" SweepDirection="Clockwise" Size="100,100"/>
                                                <LineSegment Point="100,100"/>
                                            </PathFigure.Segments>
                                        </PathFigure>
                                    </PathGeometry>
                                </GeometryDrawing.Geometry>
                            </GeometryDrawing>

                        </DrawingGroup>
                    </DrawingImage.Drawing>
                </DrawingImage>
            </Image.Source>
        </Image>

这甚至是一个好方法吗?如果没有,生成我需要的最佳方法是什么?

真正让我困惑的是如何计算 ArcSegment 值?

            DrawingGroup drawingGroup = new DrawingGroup();
            var lastPoint = new Point(100, 0);
            for (int i = 0; i < 3; i++)
            {
                GeometryDrawing drawing = new GeometryDrawing();
                drawing.Brush = (Brush)new BrushConverter().ConvertFrom("#FF0000"); // TODO: change color

                drawing.Pen = new Pen
                {
                    Brush = (Brush)new BrushConverter().ConvertFrom("#000000")
                };

                PathSegment lineSegment1 = new LineSegment(lastPoint, true);
                lastPoint = new Point(200, 100); // TODO: calculate
                PathSegment arcSegment = new ArcSegment(lastPoint, new Size(100, 100), 0, false, SweepDirection.Clockwise, true);
                PathSegment lineSegment2 = new LineSegment(new Point(100, 100), true);
                PathFigure figure = new PathFigure(new Point(100, 100), new PathSegment[] { lineSegment1, arcSegment, lineSegment2 }, false);
                drawing.Geometry = new PathGeometry(new PathFigure[] { figure });

                drawingGroup.Children.Add(drawing);
            }

提前致谢。

4

0 回答 0