Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make TabControl Headers Scrollable in WPF

As Mentioned in Title, I want to change the header of my TabControl to be scrollable.

The reason: I have too many tabItems, and the wrapping is not the best solution in my case. so I want to change it from :

Wrapping behaviour

To something like that (Scroll bar indicated by the arrow) :

scrolling behaviour

Can anyone help me and show how to do that ? (I'm using wpf)

like image 244
NTinkicht Avatar asked Nov 05 '14 18:11

NTinkicht


1 Answers

Changing TabControl.Template to something simple like this seems to work for me

<TabControl ...>
    <TabControl.Template>
        <ControlTemplate TargetType="{x:Type TabControl}">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled">
                    <TabPanel x:Name="HeaderPanel" IsItemsHost="True" Margin="0,4,0,0"/>
                </ScrollViewer>
                <ContentPresenter x:Name="PART_SelectedContentHost" Margin="4" ContentSource="SelectedContent" Grid.Row="1"/>
            </Grid>
        </ControlTemplate>
    </TabControl.Template>
</TabControl>
like image 165
dkozl Avatar answered Nov 03 '22 04:11

dkozl