样式WPF ScrollViewer出现像VS2010 Tabs Scroller

时间:2011-10-24 13:26:56

标签: wpf wpf-controls

我正在使用AvalonDock开发一个供我们的开发人员和QA内部使用的工具。我正在研究主题中提供的VS2010风格的自定义版本。风格不像VS2010那样功能不足以让我满意。我几乎完成了所有的颜色和图像更改,我只是注意到,当标题区域中有多个标签超出标题区域时,DocumentPane中的标签不会像VS2010那样滚动。

由于我在项目中拥有完整的样式,因此我找到了应用样式的区域。我在广告周围放置了一个ScrollViewer:DocumentTabPanel认为我可以以某种方式重新设置水平滚动条,以便在标签的左侧和右侧有一个箭头。

这可能吗?

Example of overflow scrolling in VS2010

以下是基础修改后的样式,但没有对scrollviewer进行任何修改:

    <Style x:Key="{x:Type ad:DocumentPane}" TargetType="{x:Type ad:DocumentPane}">
    <Setter Property="Background" Value="{DynamicResource {ComponentResourceKey {x:Type ad:DockingManager}, {x:Static ad:AvalonDockBrushes.DefaultBackgroundBrush}}}"/>
    <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ad:DocumentPane}" >
                <ControlTemplate.Resources>
                    <ContextMenu x:Key="DocumentsListMenu" StaysOpen="True"  />
                </ControlTemplate.Resources>
                <Border 
                    Background="{TemplateBinding Background}">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <Border x:Name="PART_Header" 
                            Grid.Row="0" 
                            Focusable="False" 
                            >
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition />
                                    <ColumnDefinition Width="18"/>
                                </Grid.ColumnDefinitions>
                                <ScrollViewer HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden" CanContentScroll="True">

                                        <ad:DocumentTabPanel 
                                          x:Name="paneTabsPanel" 
                                          Panel.ZIndex ="1" 
                                          IsItemsHost="True" 
                                          TabItemStyle="{StaticResource CustomDocumentTabItemStyle}"/>

                                </ScrollViewer>
                                <Button x:Name="PART_ShowContextMenuButton" 
                                        Grid.Column="2"
                                        Width="15" Height="15" 
                                        Style="{StaticResource PaneHeaderCommandStyle}">
                                    <Image x:Name="ShowContextMenuIcon" Source="pack://application:,,,/Images/Dev2010/PinMenu.png" Width="13" Height="13" Stretch="None"/>
                                </Button>
                            </Grid>
                        </Border>
                        <Grid Grid.Row="1">
                            <Border 
                                x:Name="topBorder"
                                Height="4"
                                Background="{DynamicResource {ComponentResourceKey {x:Type ad:DockingManager}, {x:Static ad:AvalonDockBrushes.DocumentHeaderBorder}}}" 
                                CornerRadius="2,2,0,0" 
                                VerticalAlignment="Top"
                                HorizontalAlignment="Stretch"
                                >
                            </Border>
                            <Border
                                x:Name="bottomBorder"
                                Height="4"
                                Background="{DynamicResource {ComponentResourceKey {x:Type ad:DockingManager}, {x:Static ad:AvalonDockBrushes.DocumentHeaderBorder}}}" 
                                CornerRadius="0,0,2,2" 
                                VerticalAlignment="Bottom"
                                HorizontalAlignment="Stretch"
                                >
                            </Border>
                            <ContentPresenter 
                                    Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SelectedItem.Content}"
                                    Margin="0,4,0,4"
                                    KeyboardNavigation.TabNavigation="Local"
                                    KeyboardNavigation.DirectionalNavigation="Contained"
                                    KeyboardNavigation.TabIndex="1"
                                    />
                        </Grid>
                    </Grid>
                </Border>
                <ControlTemplate.Triggers>                        
                    <Trigger Property="HasItems" Value="False">
                        <Setter Property="Visibility" Value="Hidden"/>
                    </Trigger>
                    <Trigger Property="ShowHeader" Value="False">
                        <Setter Property="Visibility" Value="Collapsed" TargetName="PART_Header" />
                    </Trigger>
                    <!--<DataTrigger Binding="{Binding Path=IsMainDocumentPane, RelativeSource={RelativeSource Self}}" Value="True">
                        <Setter Property="Source" Value="pack://application:,,,/Images/Dev2010/PinDockMenu.png" TargetName="ShowContextMenuIcon"/>
                    </DataTrigger>-->

                                                <Trigger Property="ContainsActiveDocument" Value="True">
                                                    <Setter Property="Background" 
                                Value="{DynamicResource {ComponentResourceKey {x:Type ad:DockingManager}, {x:Static ad:AvalonDockBrushes.DocumentHeaderBorderSelected}}}" 
                                TargetName="topBorder"/>
                                                    <Setter Property="Background" 
                                Value="{DynamicResource {ComponentResourceKey {x:Type ad:DockingManager}, {x:Static ad:AvalonDockBrushes.DocumentHeaderBorderSelected}}}" 
                                TargetName="bottomBorder"/>
                                                </Trigger>

                                                <Trigger Property="ContainsActiveContent" Value="True">
                                                    <Setter Property="Background" 
                                Value="{DynamicResource {ComponentResourceKey {x:Type ad:DockingManager}, {x:Static ad:AvalonDockBrushes.DocumentHeaderBorderSelectedActivated}}}" 
                                TargetName="topBorder"/>
                                                    <Setter Property="Background" 
                                Value="{DynamicResource {ComponentResourceKey {x:Type ad:DockingManager}, {x:Static ad:AvalonDockBrushes.DocumentHeaderBorderSelectedActivated}}}" 
                                TargetName="bottomBorder"/>
                                                </Trigger>

                                                <EventTrigger RoutedEvent="Window.Loaded">
                                                    <BeginStoryboard>
                                                        <Storyboard>
                                                            <DoubleAnimation
                                    Storyboard.TargetProperty="Opacity"
                                    From="0" To="1"  Duration="0:0:0.200" />
                                                        </Storyboard>
                                                    </BeginStoryboard>
                                                </EventTrigger>
                                                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

1 个答案:

答案 0 :(得分:1)

我过去做过类似的事情,发现最简单的方法是隐藏ScrollViewer的ScrollBar,并在按下两个RepeatButtons时手动滚动内容。

我最初找到的代码可以找到here,但基本的想法是覆盖ScrollViewer的模板,看起来像这样:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="Auto" />
    </Grid.ColumnDefinitions>

    <RepeatButton Grid.Column="0" Command="ScrollBar.PageLeftCommand" Content="<" />
    <RepeatButton Grid.Column="2" Command="ScrollBar.PageRightCommand" Content=">" />

    <ScrollContentPresenter Grid.Column="1" Content="{TemplateBinding ScrollViewer.Content}"/>
</Grid>