Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WPF在运行时更改矩形点_Wpf_Path - Fatal编程技术网

WPF在运行时更改矩形点

WPF在运行时更改矩形点,wpf,path,Wpf,Path,我有一个WPF应用程序,我需要在运行时对其进行编程操作 我想做的是创建一条包含4条线段的路径,如下所示: 但问题是,当我更改左上方的线段时,“似乎”会在线段列表中添加一个点,即最后两个点(左下方和左上方)不再合并 我知道我错过了一些小的东西,但是请,任何帮助都将不胜感激 谢谢,Mark没关系,我想出来了,我只需要在PathFigure上设置起始点,并将该点与线段一起更改(考虑到我添加了起始点,我删除了第一个线段) 谢谢 Canvas.Left="324"

我有一个WPF应用程序,我需要在运行时对其进行编程操作

我想做的是创建一条包含4条线段的路径,如下所示:

但问题是,当我更改左上方的线段时,“似乎”会在线段列表中添加一个点,即最后两个点(左下方和左上方)不再合并

我知道我错过了一些小的东西,但是请,任何帮助都将不胜感激


谢谢,Mark

没关系,我想出来了,我只需要在PathFigure上设置起始点,并将该点与线段一起更改(考虑到我添加了起始点,我删除了第一个线段)

谢谢

          Canvas.Left="324" 
          Canvas.Top="247">
        <Path.Data>
            <PathGeometry>
                <PathFigure IsClosed="True">
                    <LineSegment Point="0.5,0.5" />
                    <LineSegment Point="355.5,0.5" />
                    <LineSegment Point="355.5,229.5" />
                    <LineSegment Point="0.5,229.5" />
                </PathFigure>
            </PathGeometry>
        </Path.Data>
    </Path>
        PathFigureCollection figures = (ThePath.Data as PathGeometry).Figures;

        Console.WriteLine("number of segments: " + figures[0].Segments.Count);

        LineSegment topLeft = figures[0].Segments[0] as LineSegment;
        LineSegment topRight = figures[0].Segments[1] as LineSegment;
        LineSegment bottomRight = figures[0].Segments[2] as LineSegment;
        LineSegment bottomLeft = figures[0].Segments[3] as LineSegment;

        topLeft.Point = new Point(topLeft.Point.X - 5, topLeft.Point.Y - 5);
        topRight.Point = new Point(topRight.Point.X + 45, topRight.Point.Y - 35);
        bottomRight.Point = new Point(bottomRight.Point.X, bottomRight.Point.Y + 35);
        bottomLeft.Point = new Point(bottomLeft.Point.X + 5, bottomLeft.Point.Y - 15);