Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Causing a UserControl to remove itself (WPF)

In winforms I usually do Parent.Controls.Remove(this); to have a UserControl remove itself. This isn't working for wpf. My control has button on it to remove the whole UserControl, any ideas how to accomplish this in wpf? Thanks in advance

like image 307
Josh Avatar asked Nov 23 '10 08:11

Josh


1 Answers

You will need to know the type of the Parent property to remove yourself from your Parent control.

All Panel type parents (Grid, WrapPanel, StackPanel) have the Children property:

i.e. for Grid:

((Grid)button.Parent).Children.Remove(this);

ContentControls (Button, ContentControl, Border) have Content:

i.e. for Button:

((Button)control.Parent).Content = null;
like image 176
Arcturus Avatar answered Oct 26 '22 23:10

Arcturus