Domanda

I am using a WrapPanel and because I want to save space I want to remove (not hide) some controls (some of them are group boxes) depending on some features.

What command should I use to remove a control?

È stato utile?

Soluzione

You can use Remove() method or its variant, such as RemoveRange() & RemoveAt(), to remove control(s) from a panel :

myWrapPanel.Children.Remove(myGroupBox);

Or simply set Visibility property to Collapsed on controls that you want to hide :

myGroupBox.Visibility = Visibility.Collpased;

That won't cause empty space reserved for those hidden controls as described in MSDN :

Visibility.Collapsed: Do not display the element, and do not reserve space for it in layout.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top