Hide only Tab Header and not TabItem on count 1

2.1k Views Asked by At

I have a TabControl that creates the TabItems from a ObservableCollection. So in my ViewModel I already have a boolean Property IsMultiple and already gets set in code. So how do I hide the Tab header completely, but still display the content of that tab. I have this:

<TabControl ItemsSource="{Binding myObservableCollection}" 
 ItemContainerStyle="{StaticResource myTabItemStyle}"
 Style="{StaticResource myTabStyle}">
  <TabControl.ItemTemplate>
    <DataTemplate>
      <TextBlock Text="{Binding myTabHeaderTextProperty}" />
    </DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
    <DataTemplate>
    <DataTemplate>
</TabControl.ContentTemplate>

Basically I want to hide the itemtemplate, note that I cant just hide the TextBlock, because the style then still is there only with empty text. I want to remove/Hide the complete Tab header.

1

There are 1 best solutions below

0
mm8 On BEST ANSWER

Set the Visibility property of the ItemContainerStyle to Collapsed:

<TabControl ItemsSource="{Binding myObservableCollection}">
    <TabControl.ItemContainerStyle>
        <Style TargetType="TabItem">
            <Setter Property="Visibility" Value="Collapsed" />
        </Style>
    </TabControl.ItemContainerStyle>
    <TabControl.ContentTemplate>
        <DataTemplate>
            <TextBlock>content...</TextBlock>
        </DataTemplate>
    </TabControl.ContentTemplate>
</TabControl>