[英]Remove specified Children element of a Grid
我需要在运行时删除Grid(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);
如果您没有包含要删除的控件的变量,则必须以某种方式识别它(标记,名称),然后在网格的子项中找到该控件,然后调用Remove
。
grid1.Children.Remove(excontrol) //edited per your edit -- this is exactly what ChrisF posted though
要么
grid1.Children.RemoveAt(index)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.