开发者

In in WPF controls, which ones are similar to `<div>` HTML tag?

开发者 https://www.devze.com 2023-01-21 02:59 出处:网络
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,

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号