Make TabControl Headers Scrollable in WPF

三世轮回 提交于 2019-12-18 17:23:13

问题


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 :

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

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


回答1:


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>


来源:https://stackoverflow.com/questions/26764401/make-tabcontrol-headers-scrollable-in-wpf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!