Disconnecting an element from any/unspecified parent container in WPF
You may write a helper class with an extension method: public static class RemoveChildHelper { public static void RemoveChild(this DependencyObject parent, UIElement child) { var panel = parent as Panel; if (panel != null) { panel.Children.Remove(child); return; } var decorator = parent as Decorator; if (decorator != null) { if (decorator.Child == child) { decorator.Child … Read more