none
在TABITEM上加滚动条 RRS feed

答案

  • 下面是TabControl默认的ControlTemplate,你参考这个进行修改TabPanel部分,比如加上一个ScrollViewer什么的~

    <Style x:Key="{x:Type TabControl}"
               TargetType="{x:Type TabControl}">
            <Setter Property="Foreground"
                    Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
            <Setter Property="Padding"
                    Value="4,4,4,4"/>
            <Setter Property="BorderThickness"
                    Value="1"/>
            <Setter Property="BorderBrush"
                    Value="{StaticResource TabControlNormalBorderBrush}"/>
            <Setter Property="Background"
                    Value="#F9F9F9"/>
            <Setter Property="HorizontalContentAlignment"
                    Value="Center"/>
            <Setter Property="VerticalContentAlignment"
                    Value="Center"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TabControl}">
                        <Grid KeyboardNavigation.TabNavigation="Local"
                              SnapsToDevicePixels="true"
                              ClipToBounds="true">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition x:Name="ColumnDefinition0"/>
                                <ColumnDefinition x:Name="ColumnDefinition1"
                                                  Width="0"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition x:Name="RowDefinition0"
                                               Height="Auto"/>
                                <RowDefinition x:Name="RowDefinition1"
                                               Height="*"/>
                            </Grid.RowDefinitions>
                            <TabPanel x:Name="HeaderPanel"
                                      Panel.ZIndex ="1" 
                                      KeyboardNavigation.TabIndex="1"
                                      Grid.Column="0"
                                      Grid.Row="0"
                                      Margin="2,2,2,0"
                                      IsItemsHost="true"/>
                            <Border x:Name="ContentPanel"
                                    Background="{TemplateBinding Background}"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    BorderBrush="{TemplateBinding BorderBrush}"
                                    KeyboardNavigation.TabNavigation="Local"
                                    KeyboardNavigation.DirectionalNavigation="Contained"
                                    KeyboardNavigation.TabIndex="2"
                                    Grid.Column="0"
                                    Grid.Row="1">
                                <ContentPresenter x:Name="PART_SelectedContentHost"
                                                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                                  Margin="{TemplateBinding Padding}"
                                                  ContentSource="SelectedContent"/>
                            </Border>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="TabStripPlacement"
                                     Value="Bottom">
                                <Setter Property="Grid.Row"
                                        Value="1"
                                        TargetName="HeaderPanel"/>
                                <Setter Property="Grid.Row"
                                        Value="0"
                                        TargetName="ContentPanel"/>
                                <Setter Property="Height"
                                        Value="*"
                                        TargetName="RowDefinition0"/>
                                <Setter Property="Height"
                                        Value="Auto"
                                        TargetName="RowDefinition1"/>
                                <Setter Property="Margin"
                                        Value="2,0,2,2"
                                        TargetName="HeaderPanel"/>
                            </Trigger>
                            <Trigger Property="TabStripPlacement"
                                     Value="Left">
                                <Setter Property="Grid.Row"
                                        Value="0"
                                        TargetName="HeaderPanel"/>
                                <Setter Property="Grid.Row"
                                        Value="0"
                                        TargetName="ContentPanel"/>
                                <Setter Property="Grid.Column"
                                        Value="0"
                                        TargetName="HeaderPanel"/>
                                <Setter Property="Grid.Column"
                                        Value="1"
                                        TargetName="ContentPanel"/>
                                <Setter Property="Width"
                                        Value="Auto"
                                        TargetName="ColumnDefinition0"/>
                                <Setter Property="Width"
                                        Value="*"
                                        TargetName="ColumnDefinition1"/>
                                <Setter Property="Height"
                                        Value="*"
                                        TargetName="RowDefinition0"/>
                                <Setter Property="Height"
                                        Value="0"
                                        TargetName="RowDefinition1"/>
                                <Setter Property="Margin"
                                        Value="2,2,0,2"
                                        TargetName="HeaderPanel"/>
                            </Trigger>
                            <Trigger Property="TabStripPlacement"
                                     Value="Right">
                                <Setter Property="Grid.Row"
                                        Value="0"
                                        TargetName="HeaderPanel"/>
                                <Setter Property="Grid.Row"
                                        Value="0"
                                        TargetName="ContentPanel"/>
                                <Setter Property="Grid.Column"
                                        Value="1"
                                        TargetName="HeaderPanel"/>
                                <Setter Property="Grid.Column"
                                        Value="0"
                                        TargetName="ContentPanel"/>
                                <Setter Property="Width"
                                        Value="*"
                                        TargetName="ColumnDefinition0"/>
                                <Setter Property="Width"
                                        Value="Auto"
                                        TargetName="ColumnDefinition1"/>
                                <Setter Property="Height"
                                        Value="*"
                                        TargetName="RowDefinition0"/>
                                <Setter Property="Height"
                                        Value="0"
                                        TargetName="RowDefinition1"/>
                                <Setter Property="Margin"
                                        Value="0,2,2,2"
                                        TargetName="HeaderPanel"/>
                            </Trigger>
                            <Trigger Property="IsEnabled" 
                                     Value="false">
                                <Setter Property="Foreground" 
                                        Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

    2012年11月18日 11:45