You will need to find out the type of property Parentin order to remove itself from your parent control.
All parents of the Panel type (Grid, WrapPanel, StackPanel) have the property Children:
i.e. for mesh:
((Grid)button.Parent).Children.Remove(this);
ContentControls (Button, ContentControl, Border) has content:
i.e. for button:
((Button)control.Parent).Content = null;
source
share