我需要在运行时删除网格 (grid1) 的指定元素。这是我添加元素的代码。
examControls.Add(excontrol); // add the element on the ArrayList
excontrol.Margin = new Thickness(x, y + margin, 0, 0);
grid1.Children.Add(excontrol);
如何在运行时删除指定的“excontrol”元素(在运行时添加)?
提前致谢
最佳答案
如果您保留控件的记录,您可以简单地执行以下操作:
grid1.Children.Remove(excontrol);
如果您没有保存要删除的控件的变量,则必须以某种方式(Tag、Name)识别它,然后在网格的子项中找到该控件,然后调用 Remove
。
关于c# - 删除 Grid 的指定子元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15621080/