隐藏 TabControl 标头
编程方式是什么(即不使用这个问题中的样式,而是使用code) 隐藏 TabControl
标头?我会很高兴得到一个片段。
What's the programmatic way (ie not using styles as in this question, but using code) to hide the TabControl
header? I'll be glad for a snippet.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
实际上,隐藏标签栏非常简单。您只需将每个
TabItem
的Visibility
设置为Collapsed
即可。您仍然可以看到选项卡内容,...只是看不到选项卡标题本身。Actually, it's very straight forward to hide the tab strip. You just set each
TabItem
sVisibility
toCollapsed
. You still see the tab content,...just not the tab header itself.简单的XAML风格
Simple XAML Style
嗯,有几种方法可以做到这一点。
最丑陋的方法:使用 VisualTreeHelper 查找 TabPanel(或用于托管项目的任何其他面板),并将其 Visibility 属性设置为 Visibility.Collapsed。为什么丑?如果您不够小心,很容易在此处创建一些烦人的错误,或者通过“无害”样式更新来破坏此方法...
我更喜欢使用 Xaml 和代码隐藏的组合。您可以将 TabItem 的可见性绑定到视图模型属性,或将 TabPanel 的可见性绑定到视图模型属性。在这两种情况下,您都必须覆盖样式(ItemContainer 的样式或整个 TabControl 的样式)。在这两种情况下,您都有视图模型。现在,要切换选项卡标题的可见性,您只需更新视图模型中的属性即可。以下是 TabItem 的示例:
XAML
C#
Well, there are several ways to do this.
The ugliest way: Use VisualTreeHelper to find TabPanel (or any other Panel you use to host items), and set it's Visibility property to Visibility.Collapsed. Why ugly? It's easy to create few annoying bugs here or break this approach with 'harmless' style update if you was not careful enough...
I prefer using combination of Xaml and code behind. You bind either TabItem's visibility to view model property or TabPanel's visibility to view model property. In both cases you have to override style (either ItemContainer's style or whole TabControl's style). In both cases you have view model. Now, to toggle tab header's visibility, you just update a property in the view model. Here is an example with TabItems:
XAML
C#
我在一些代码中尝试过这个,我手动填充选项卡项目...
...但是后来发生了一件奇怪的事情,第二次我清除选项卡控件的项目,再次创建选项卡项目并使用这种方法在将其添加到选项卡控件之前,整个选项卡项及其内容都消失了,而不仅仅是选项卡标题。因此,我在相当于 此解决方案:
I've tried this in some code where I populate the tab items manually...
...but then I had a weird thing happen where the second time I'd clear out the tab control's items, create the tab item again and use this approach before adding it to the tab control, the entire tab item and its contents were gone, not just the tab header. So I've had success with the programmatic equivalent of this solution:
如果您使用 C# 并为 TabItem 设置 x:Name,您还可以像这样操作 Visibility:
If you use C# and set the x:Name for the TabItem, you can also manipulate the Visibility like so: