I need to wrap a group of WPF controls to that I can toggle their visi开发者_StackOverflow中文版bility at the same time. How can I do that?
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.
Use StackPanel
or other kinds of panels depending on your need (WrapPanel
if you need wrapping).
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.
You can use any of the layout panels: StackPanel
, DockPanel
, WrapPanel
or Grid
.
精彩评论