Windows 8 中的 ScrollViewer:始终显示垂直滚动条 [英] ScrollViewer in Windows 8: always show vertical scrollbar

查看:33
本文介绍了Windows 8 中的 ScrollViewer:始终显示垂直滚动条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何始终在滚动查看器中显示垂直滚动条?

How always show vertical scrollbar in the scrollviewer?

它会在几秒钟内消失,但我想让滚动可用时始终可见

It disappear in few seconds, but I want to make scroll visible all the time when scrolling is available

感谢您的帮助

推荐答案

我认为 Windows 8 Consumer Preview 中的控件可能存在错误,因为以下应该正常工作:

I think there might be a bug in the control in Windows 8 Consumer Preview, since the following should normally work:

<ScrollViewer
    Style="{StaticResource VerticalScrollViewerStyle}"
    VerticalScrollBarVisibility="Visible"
    Template="{StaticResource ScrollViewerControlTemplate1}">

作为一种解决方法,您可以修改 ScrollViewer 的模板:

As a workaround you can modify the template of the ScrollViewer:

<ScrollViewer
    Style="{StaticResource VerticalScrollViewerStyle}"
    Template="{StaticResource ScrollViewerControlTemplate1}">

... 在某些 ResourceDictionary 中的其他地方 - 删除了NoIndicator"VisualState 的修改后的标准 ScrollViewer 模板.

... elsewhere in some ResourceDictionary - the modified standard ScrollViewer template with the "NoIndicator" VisualState removed.

    <ControlTemplate
        x:Key="ScrollViewerControlTemplate1"
        TargetType="ScrollViewer">
        <Border
            BorderBrush="{TemplateBinding BorderBrush}"
            BorderThickness="{TemplateBinding BorderThickness}">
            <VisualStateManager.VisualStateGroups>
                <VisualStateGroup
                    x:Name="ScrollingIndicatorStates">
                    <VisualState
                        x:Name="TouchIndicator">
                        <Storyboard>
                            <FadeOutThemeAnimation
                                TargetName="ScrollBarSeparator" />
                            <ObjectAnimationUsingKeyFrames
                                Storyboard.TargetName="VerticalScrollBar"
                                Storyboard.TargetProperty="IndicatorMode"
                                Duration="0">
                                <DiscreteObjectKeyFrame
                                    KeyTime="0">
                                    <DiscreteObjectKeyFrame.Value>
                                        <ScrollingIndicatorMode>TouchIndicator</ScrollingIndicatorMode>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                            </ObjectAnimationUsingKeyFrames>
                            <ObjectAnimationUsingKeyFrames
                                Storyboard.TargetName="HorizontalScrollBar"
                                Storyboard.TargetProperty="IndicatorMode"
                                Duration="0">
                                <DiscreteObjectKeyFrame
                                    KeyTime="0">
                                    <DiscreteObjectKeyFrame.Value>
                                        <ScrollingIndicatorMode>TouchIndicator</ScrollingIndicatorMode>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                    <VisualState
                        x:Name="MouseIndicator">
                        <Storyboard>
                            <FadeInThemeAnimation
                                TargetName="ScrollBarSeparator" />
                            <ObjectAnimationUsingKeyFrames
                                Storyboard.TargetName="VerticalScrollBar"
                                Storyboard.TargetProperty="IndicatorMode"
                                Duration="0">
                                <DiscreteObjectKeyFrame
                                    KeyTime="0">
                                    <DiscreteObjectKeyFrame.Value>
                                        <ScrollingIndicatorMode>MouseIndicator</ScrollingIndicatorMode>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                            </ObjectAnimationUsingKeyFrames>
                            <ObjectAnimationUsingKeyFrames
                                Storyboard.TargetName="HorizontalScrollBar"
                                Storyboard.TargetProperty="IndicatorMode"
                                Duration="0">
                                <DiscreteObjectKeyFrame
                                    KeyTime="0">
                                    <DiscreteObjectKeyFrame.Value>
                                        <ScrollingIndicatorMode>MouseIndicator</ScrollingIndicatorMode>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
            <Grid
                Background="{TemplateBinding Background}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition
                        Width="*" />
                    <ColumnDefinition
                        Width="Auto" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition
                        Height="*" />
                    <RowDefinition
                        Height="Auto" />
                </Grid.RowDefinitions>
                <ScrollContentPresenter
                    x:Name="ScrollContentPresenter"
                    Grid.RowSpan="2"
                    Grid.ColumnSpan="2"
                    ContentTemplate="{TemplateBinding ContentTemplate}"
                    Margin="{TemplateBinding Padding}" />
                <ScrollBar
                    x:Name="VerticalScrollBar"
                    Grid.Column="1"
                    IsTabStop="False"
                    Maximum="{TemplateBinding ScrollableHeight}"
                    Margin="1,0,0,0"
                    Orientation="Vertical"
                    Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"
                    Value="{TemplateBinding VerticalOffset}"
                    ViewportSize="{TemplateBinding ViewportHeight}"
                    HorizontalAlignment="Right" />
                <ScrollBar
                    x:Name="HorizontalScrollBar"
                    IsTabStop="False"
                    Maximum="{TemplateBinding ScrollableWidth}"
                    Margin="0,1,0,0"
                    Orientation="Horizontal"
                    Grid.Row="1"
                    Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"
                    Value="{TemplateBinding HorizontalOffset}"
                    ViewportSize="{TemplateBinding ViewportWidth}" />
                <Rectangle
                    x:Name="ScrollBarSeparator"
                    Grid.Row="1"
                    Grid.Column="1"
                    Margin="1,1,0,0"
                    StrokeThickness="1"
                    Fill="{StaticResource ScrollBarTrackBrush}"
                    Stroke="{StaticResource ScrollBarTrackBorderBrush}" />
            </Grid>
        </Border>
    </ControlTemplate>

这篇关于Windows 8 中的 ScrollViewer:始终显示垂直滚动条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆