WPF - TabItem 内容在 tabitem.visibility=hidden 时仍然可见

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12949890/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 05:48:59  来源:igfitidea点击:

WPF - TabItem Contents still visible when tabitem.visibility=hidden

c#.netwpf

提问by aioracle

Is there any good solution to this problem.

这个问题有没有好的解决办法。

I have set the

我已经设置了

tabitem.visibility=hidden

tabitem.visibility=隐藏

but the contents in this tabitem is still visible. I want to hide all the contents of tabitems.

但是这个tabitem中的内容仍然可见。我想隐藏tabitems的所有内容。

I did search for a resolution but no luck. In 2009 someone raised this issue but still NOW there is no result on how to achieve this. URL: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/e4d23ace-0eb5-45a9-86f5-43c6351cb0ed/

我确实寻找了解决方案,但没有运气。2009 年有人提出了这个问题,但现在仍然没有关于如何实现这一目标的结果。网址:http: //social.msdn.microsoft.com/Forums/en-US/wpf/thread/e4d23ace-0eb5-45a9-86f5-43c6351cb0ed/

Thanks

谢谢

回答by MrDosu

To fix your problem use Visibility.Collapsed. Visibility.Hidden won't change the layout and so you would always have that empty space in the tab header. Be sure to change the selected tab as well when that happens.

要解决您的问题,请使用 Visibility.Collapsed。Visibility.Hidden 不会更改布局,因此您将始终在选项卡标题中留出空白空间。发生这种情况时,请务必更改选定的选项卡。

I wouldn't recommend hiding tab items like that though. Conceptually they are either open or closed.

不过,我不建议隐藏这样的选项卡项目。从概念上讲,它们要么是开放的,要么是封闭的。

回答by Akku

Try to hide the TabControl by setting it's visibility to Visibility.Hidden or switch to another tab (maybe an empty one?). You didn't give much reason why you do it, but if you really want to hide all controls in the tabcontrol, you can also iterate through tabItem.Children and set their Visibility to Visibility.Hidden.

尝试通过将 TabControl 的可见性设置为 Visibility.Hidden 或切换到另一个选项卡(可能是空的?)来隐藏它。你没有给出你为什么这样做的太多理由,但如果你真的想隐藏 tabcontrol 中的所有控件,你也可以遍历 tabItem.Children 并将它们的 Visibility 设置为 Visibility.Hidden。