I want to remove a suppose control whose type is of border, from the grid control. how can I achieve it in WPF C# ?
Sorry Guys, My problem is that I have grid control which has GUI design at XAML end and user control which are added using C# and the some controls are overlapped. Some controls are removed but some are left which overlap one another. How can I remove all controls. The code you have posted work for control which are not overlapped but for overlapped ones, it didn't work.
Here is my code:
int intTotalChildren = grdGrid.Children.Count-1;
for (int intCounter = intTotalChildren; intCounter > 0; intCounter--)
{
if (grdGrid.Children[intCounter].GetType() == typeof(Border))
{
Border ucCurrentChild = (Border)grdGrid.Children[intCounter];
grdGrid.Children.Remove(ucCurrentChild);
}
}
My error was that each time I used the Children.Count in the for loop and every time I removed a child, the Children.Count changed and not all children were removed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With