WPF - two rows of tabs in a tab control - tab wrap

2019-07-18 02:55发布

问题:

I have a WPF TabControl with a large number of tabs and they are presented in a sequential line all across the screen. Which means that a user needs to scroll sideways in order to view all the tabs.

Is there a way to create two rows of tabs or make the long row of tabs "wrap" into two or more rows?

回答1:

Wrapping is the default behavior for TabControls. Any Style or ControlTemplate you're using that interferes with that?

The following code:

<Window x:Class="WpfApplication1.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window1" Height="300" Width="300" AllowsTransparency="True" WindowStyle="None">
    <Grid>
        <TabControl>
            <TabItem Header="TabItem"/>
            <TabItem Header="TabItem"/>
            <TabItem Header="TabItem"/>
            <TabItem Header="TabItem"/>
            <TabItem Header="TabItem"/>
            <TabItem Header="TabItem"/>
            <TabItem Header="TabItem"/>
            <TabItem Header="TabItem"/>
            <TabItem Header="TabItem"/>
            <TabItem Header="TabItem"/>
            <TabItem Header="TabItem"/>
        </TabControl>
    </Grid>
</Window>

yields