【发布时间】:2019-04-26 22:58:14
【问题描述】:
我正在从一个循环中画出一系列线条(省略不重要的东西):
for (int i = 0; i < TLS.NumEdges - 10; i++)
{
MSTLine.X1 = BlueArmy[TLS.EdgeList[i, 0]].Location.X;
MSTLine.Y1 = BlueArmy[TLS.EdgeList[i, 1]].Location.Y;
MSTLine.X2 = BlueArmy[TLS.EdgeList[i + 1, 0]].Location.X;
MSTLine.Y2 = BlueArmy[TLS.EdgeList[i + 1, 0]].Location.Y;
((MainWindow)System.Windows.Application.Current.MainWindow).AICanvas.Children.Add(MSTLine);
}
它会抛出这个运行时错误: System.ArgumentException: '指定的 Visual 已经是另一个 Visual 的子对象或 CompositionTarget 的根。'
我认为它不喜欢多个 Children.Add 调用。那么从循环内部绘制一系列线的正确方法是什么?由于其他原因,我宁愿不使用折线。
【问题讨论】: