gpt4 book ai didi

c# - 在 Windows Phone 7 中画线?

转载 作者:太空宇宙 更新时间:2023-11-03 14:11:26 25 4
gpt4 key购买 nike

我想用路径画一些线。运行程序时它总是显示错误。错误发生在这句话:“myPathSegmentCollection.Add(myLineSegment[i]);”可以构建解决方案。调试时显示“元素已经是另一个元素的子元素”

以下是我的功能:

public void drawline(Point endP)
{
PathFigenter code hereure myPathFigure = new PathFigure();
myPathFigure.StartPoint = endP;

LineSegment [] myLineSegment = new LineSegment[5];
Point myPoint = new Point();
LineSegment line = new LineSegment();
PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();
for (int i = 0; i < 5; i++)
{
myPoint.X = i + 10.0;
myPoint.Y = i+1.0;
line.Point = myPoint;
myLineSegment[i] = line;
myPathSegmentCollection.Add(myLineSegment[i]);
}

myPathFigure.Segments = myPathSegmentCollection;

PathFigureCollection myPathFigureCollection = new PathFigureCollection();
myPathFigureCollection.Add(myPathFigure);

PathGeometry myPathGeometry = new PathGeometry();
myPathGeometry.Figures = myPathFigureCollection;

myPath.StrokeThickness = 1;
myPath.Data = myPathGeometry;
}

有没有人可以帮忙?谢谢!

最佳答案

问题是您在循环中重新使用了 LineSegment。这些只能作为单个控件的父级,因此多次尝试添加相同的项目会引发异常。

要修复它,请在循环中创建一个新的 LineSegment:

for (int i = 0; i < 5; i++)
{
myLineSegment[i] = new LineSegment() {
Point = new Point(i + 10.0, i + 1.0);
};
myPathSegmentCollection.Add(myLineSegment[i]);
}

关于c# - 在 Windows Phone 7 中画线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7749038/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com