Remove specified Children element of a Grid

c#, children, grid, wpf

Solution

If you keep a record of the control you can simply do:

grid1.Children.Remove(excontrol);

If you don't have a variable that holds the control you wish to remove you'll have to identify it in some way (Tag, Name), then find that control in the grid's children and then call `Remove`.

Problem

I need to remove at runtime a specified element of a Grid (grid1). This is the code where i add the elements. ``` examControls.Add(excontrol); // add the element on the ArrayList excontrol.Margin = new Thickness(x, y + margin, 0, 0); grid1.Children.Add(excontrol); ``` How can i remove at runtime a specified "excontrol" element (added at runtime) ? Thanks in advance

Original source