WPF多行TabControl无需重新排列行

时间:2011-04-04 13:02:24

标签: wpf tabcontrol

当水平尺寸太小时,WPF TabControl及其默认TabPanel将标签项排列为多行。然后选项卡选择会更改这些行的顺序,因此选定的选项卡项始终位于第一行。

我发现了一些关于如何将TabPanel替换为另一个项目控件的文章,因此他们获得滚动标签而不是多行为行为。

我想保留多行(不滚动),但禁用行的重新排列。创建选项卡后,无论选择如何更改,它们都应保持原位。这可能吗?

2 个答案:

答案 0 :(得分:3)

你试过用这样的东西覆盖默认样式吗?即:使用wrappanel而不是TabPanel?

<Style x:Key="{x:Type TabControl}" TargetType="{x:Type TabControl}">        
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type TabControl}">                    
                <Grid TabNavigation="Local" SnapsToDevicePixels="true" ClipToBounds="true">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Name="ColumnDefinition0" />
                        <ColumnDefinition Name="ColumnDefinition1" Width="0" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Name="RowDefinition0" Height="Auto" />
                        <RowDefinition Name="RowDefinition1" Height="*" />
                    </Grid.RowDefinitions>
                    <WrapPanel Name="HeaderPanel" ZIndex="1" TabIndex="1" Column="0" Row="0" Margin="2,2,2,0" IsItemsHost="true" />
                    <Border Name="ContentPanel" Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" TabNavigation="Local" DirectionalNavigation="Contained" TabIndex="2" Column="0" Row="1">
                        <ContentPresenter Name="PART_SelectedContentHost" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Margin="{TemplateBinding Padding}" ContentSource="SelectedContent" />
                    </Border>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

答案 1 :(得分:0)

我找到的唯一解决方案是修改框架的TabPanel类,使其int GetActiveRow(int[] solution)方法始终返回0.虽然这解决了问题,但我不确定以这种方式使用框架的源是合法的。

相关问题