Make TabControl Headers Scrollable in WPF

前端 未结 1 2049
抹茶落季
抹茶落季 2021-01-03 00:53

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

相关标签:
1条回答
  • 2021-01-03 01:19

    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>
    
    0 讨论(0)
提交回复
热议问题