1
votes

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
What have you tried? Please provide a good minimal reproducible example that shows your attempt, explain what that code does, and how exactly that's different from what you want. - Peter Duniho
you want to do this only when there is a single item in your collection, right? - Parag

1 Answers

2
votes

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>