views:

47

answers:

4

I need to wrap a group of WPF controls to that I can toggle their visibility at the same time. How can I do that?

+5  A: 

Use StackPanel or other kinds of panels depending on your need (WrapPanel if you need wrapping).

Aliostad
+1  A: 

You can use any of the layout panels: StackPanel, DockPanel, WrapPanel or Grid.

Jackson Pope
+2  A: 

StackPanel, DockPanel, WrapPanel are mainly used for design, to align the controls in a specific way. Therefor i would use the Grid.

All of these can be used, but using a Panel just for hide and seek would make it lose its meaning.

GxG
+1  A: 

Any of the panels - Grid, stackpanel, canvas, etc - in WPF can be Visible/Collapsed/Hidden. Just set the visibility of the object to Visibility.Hidden or Visibility.Collapsed. Notice the Name="" attribute...

<StackPanel Name="Test" Visibility="Visible">  
     ...  
</StackPanel>  

On the code-behind, do a simple Name.Visibility conversion:

Test.Visibility = Visibility.Visible;
Test.Visibility = Visibility.Collapsed;
Test.Visibility = Visibility.Hidden;

It's also worth noting that most (if not all?) objects have Visibility. Buttons, menu items, etc, etc... Button Name="MyButton, Mybutton.Visibility =...

Edit: Link I posted wasn't helpful.

WernerCD