动态删除元素

时间:2012-09-10 21:21:30

标签: c# windows-phone-7 canvas

我在canvas内动态绘制了一些线条。如何使用C#删除它们? 我试过了:

for (int ix = this.canvas1.Children.Count - 1; ix >= 0; ix--)
if (this.canvas1.Children[ix] is Line) this.canvas1.Children[ix].Dispose();

但系统不接受Dispose作为方法。

2 个答案:

答案 0 :(得分:0)

尝试通过Canvas.Children集合循环遍历所有项目,并删除或删除要删除的不可见项目。

答案 1 :(得分:0)

这是问题的解决方案

for (int ix = this.canvas1.Children.Count - 1; ix >= 0; ix--)
      {
          if (this.canvas1.Children[ix] is Line) this.canvas1.Children.RemoveAt(ix);
            }