Remove Child Elements from WPF Panel

by ixmx


This Extension Method shows how to remove Rectangle elements from Panel container.
Many objects derive from Panel. There are six defined panel classes (Canvas, DockPanel, Grid, StackPanel, VirtualizingStackPanel, WrapPanel)


public static class MyExtentions
{
    public static void RemoveRectangles(this Panel panel)
    {
        var children = from UIElement c in panel.Children where c is Rectangle select c;
        foreach (UIElement u in children)
        {
            panel.Children.Remove(u);
        }
    }
}
Advertisements