Causing UserControl Removal (WPF)

In winforms, I usually do Parent.Controls.Remove(this);to remove UserControl. This does not work for wpf. My control has a button on it to remove the entire UserControl, any ideas on how to do this in wpf? thanks in advance

+5
source share
1 answer

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;
+8
source

All Articles