Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
323 views
in Technique[技术] by (71.8m points)

Hide Tab headers in WPF TabControl

What is the best way to hide Tab headers when there is only a single visible Tab?

I want to hide TabControl chrome completely, while leaving the content of the Tab visible.

question from:https://stackoverflow.com/questions/387480/hide-tab-headers-in-wpf-tabcontrol

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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>

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...