我在WPF中更新for循环中的画布时遇到问题。 在我的应用程序中,我有来自很多帧的贴图的数据,我想绘制彼此相邻的2种不同录音的图形。我知道绘图功能有效,但我不能让我的代码不断更新画布。我只能看到最后一帧的贴图。我知道,对于其他框架,正在计算粘贴数,但它们没有显示在画布上。
我使用PolyLine函数绘制了stickfigures。
这是我使用的for循环。
for (int i = 0; i < recording1.Count; i++)
{
skeletCanvas1.Children.Clear();
skeletCanvas2.Children.Clear();
skeletCanvas1.Children.Add(drawLine(points1((double[])recording1[i]), brush1));
skeletCanvas1.Children.Add(drawLine(points2((double[])recording1[i]), brush1));
skeletCanvas1.Children.Add(drawLine(points3((double[])recording1[i]), brush1));
skeletCanvas1.Children.Add(drawLine(points4((double[])recording1[i]), brush1));
skeletCanvas1.Children.Add(drawLine(points5((double[])recording1[i]), brush1));
skeletCanvas2.Children.Add(drawLine(points1((double[])recording2[i]), brush2));
skeletCanvas2.Children.Add(drawLine(points2((double[])recording2[i]), brush2));
skeletCanvas2.Children.Add(drawLine(points3((double[])recording2[i]), brush2));
skeletCanvas2.Children.Add(drawLine(points4((double[])recording2[i]), brush2));
skeletCanvas2.Children.Add(drawLine(points5((double[])recording2[i]), brush2));
skeletCanvas1.UpdateLayout();
skeletCanvas2.UpdateLayout();
System.Threading.Thread.Sleep(100);
}
感谢您的帮助。
答案 0 :(得分:0)
您无法在GUI上看到任何更新,因为您的单线程应用程序正在使用GUI线程循环。解决方案可能是使用计时器或辅助线程。