在 WPF TabControl 中隐藏 Tab 标头 [英] Hide Tab headers in WPF TabControl
本文介绍了在 WPF TabControl 中隐藏 Tab 标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当只有一个可见的 Tab 时,隐藏 Tab 标题的最佳方法是什么?
What is the best way to hide Tab headers when there is only a single visible Tab?
我想完全隐藏 TabControl 镶边,同时让 Tab 的内容可见.
I want to hide TabControl chrome completely, while leaving the content of the Tab visible.
推荐答案
您可以将应用于 TabItem 的 Style 与 DataTrigger 一起使用,如果父 TabControl 只有一项,它将折叠它:
You can use a Style applied to TabItem with a DataTrigger that will collapse it if the parent TabControl has only one item:
<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid.Resources>
<x:Array x:Key="tabData" Type="{x:Type sys:String}">
<sys:String>do</sys:String>
<sys:String>re</sys:String>
<sys:String>mi</sys:String>
</x:Array>
</Grid.Resources>
<TabControl ItemsSource="{StaticResource tabData}">
<TabControl.ItemContainerStyle>
<Style TargetType="{x:Type TabItem}">
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TabControl}}, Path=Items.Count}" Value="1">
<Setter Property="Visibility" Value="Collapsed"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TabControl.ItemContainerStyle>
</TabControl>
</Grid>
如果您想在只有一项的情况下完全摆脱 TabControl,那么该逻辑可能应该在更高的级别.
If you want to get rid of the TabControl completely if there is only one item, that logic should probably be at a higher level.
这篇关于在 WPF TabControl 中隐藏 Tab 标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文