Jiho Han
Jiho Han

Reputation: 1630

WPF TabControl show tabs only no content

The idea is to simply use the tabs (headers) to make a selection. So the "content" is unnecessary. And I can't seem to find an easy way to make the content "empty" or take up zero height.

So visually, you should only be presented with tabs, nothing else.

Upvotes: 3

Views: 2159

Answers (4)

7dino7
7dino7

Reputation: 21

Another way to pull this off:

<TabControl Padding="0" BorderThickness="0">
    <TabControl.ContentTemplate>
        <DataTemplate>
            <Grid/>
        </DataTemplate>
    </TabControl.ContentTemplate>
</TabControl>

Upvotes: 0

Dragos Bursacovschi
Dragos Bursacovschi

Reputation: 336

To hide the content of the tabs you can override the ContentTemplate of the TabControl.

<TabControl>
    <TabControl.ContentTemplate>
         <DataTemplate/>
    </TabControl.ContentTemplate>
</TabControl>

Upvotes: 2

Flot2011
Flot2011

Reputation: 4671

You can use overlapped tab shaped buttons, you do not really need a tab control.

Here is how to create custom shaped buttons in WPF.

And here is how to create a tab shaped button.

Upvotes: 0

Alex Hope O&#39;Connor
Alex Hope O&#39;Connor

Reputation: 9694

Could you customise the ControlTemplate from the MSDN example and remove the selected content: https://msdn.microsoft.com/en-us/library/ms754137(v=vs.90).aspx

So it would become something like this:

<Style  TargetType="{x:Type TabControl}">
  <Setter Property="OverridesDefaultStyle" Value="True" />
  <Setter Property="SnapsToDevicePixels" Value="True" />
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="{x:Type TabControl}">
        <Grid KeyboardNavigation.TabNavigation="Local">
          <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
          </Grid.RowDefinitions>
          <TabPanel 
            Name="HeaderPanel"
            Grid.Row="0"
            Panel.ZIndex="1" 
            Margin="0,0,4,-1" 
            IsItemsHost="True"
            KeyboardNavigation.TabIndex="1"
            Background="Transparent" />
        </Grid>
        <ControlTemplate.Triggers>
          <Trigger Property="IsEnabled" Value="False">
            <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}" />
          </Trigger>
        </ControlTemplate.Triggers>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

Upvotes: 1

Related Questions