none
如何让ScrollViewer的滚动条一直显示? RRS feed

  • 问题

  • 请问如何让scrollViewer的滚动条一直显示?

    我的ScrollViewer是布局在一个UC中的Grid里面,scrollViewer里面有个Grid(该Grid比ScrollViewer长度要长)。

    我的ScrollViewer横向滚动条设置: HorizontalScrollMode="Enabled", HorizontalScrollBarVisibility="Visible"

    这样滚动条在鼠标或触点经过时出现了,但是鼠标或者触点离开该UC后几秒,滚动条会淡出隐藏。

    我希望该滚动条从界面加载UC开始就一直显示,不管鼠标或触点经过与否,请问该如何做呢?

    2013年11月1日 7:34

答案

  • Hi KK0603,

    刚测了下你的代码,的确有类似问题出现,不过我对UserControl设置了CacheMode为BitmapCache之后,就可以不论何时都能显示ScrollBar,你可以测试一下。请参考http://msdn.microsoft.com/zh-cn/library/windows/apps/windows.ui.xaml.uielement.cachemode.aspx

    以上请参考。

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    2013年11月8日 16:08
    版主

全部回复

  • Hi KK0603

    我测试了下,没有问题啊。不管ScrollViewer当中的Grid是大是小,始终都会显示横向和纵向的滚动条。

    我的代码如下,

    XAML:

            <UserControl HorizontalAlignment="Left" Height="289" Margin="63,57,0,0" VerticalAlignment="Top" Width="841">
                <Grid HorizontalAlignment="Left" Height="269" Margin="0,10,0,0" VerticalAlignment="Top" Width="831">
                    <ScrollViewer x:Name="srw">
                        <Grid Height="167" Width="536"/>//大小可以自己更改
                    </ScrollViewer>
                </Grid>
            </UserControl>

    Backend:

    srw.HorizontalScrollMode = ScrollMode.Enabled;
    srw.HorizontalScrollBarVisibility = ScrollBarVisibility.Visible;
    srw.VerticalScrollBarVisibility = ScrollBarVisibility.Visible;
    srw.VerticalScrollMode = ScrollMode.Enabled;
    或者如果你有可以重现问题的demo,请share给我以便分析问题所在。


    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    2013年11月1日 15:44
    版主
  • 谢谢回复,但是问题依旧没有解决

    我写了个demo

    UC如下:

    <UserControl
        x:Class="App2.MyUserControl1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:App2"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        d:DesignHeight="300"
        d:DesignWidth="400">
        
        <Grid>
            <ScrollViewer x:Name="srw"
                          HorizontalScrollBarVisibility="Visible"
                          HorizontalScrollMode="Enabled"
                          VerticalScrollBarVisibility="Visible"
                          VerticalScrollMode="Enabled">
                <Grid>
                    <TextBlock Text="MyUCWithScrollViewer" FontSize="36" HorizontalAlignment="Center" VerticalAlignment="Center" />
                </Grid>
            </ScrollViewer>
        </Grid>
    </UserControl>

    MainPage中调用UC:

    <Page
        x:Class="App2.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:App2"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d">
    
        <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <TextBlock Text="Row1" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="36"/>
            <local:MyUserControl1 Grid.Row="1"/>
        </Grid>
    </Page>
    运行后鼠标移动到UC上显示滚动条,但是鼠标回到MainPage中grid第一行后5秒,滚动条淡出隐藏。我想让它一直显示。
    2013年11月4日 2:17
  • 你好 KK0603,

    你的这个问题暂时无法解决。

    你无法控制滚动条一直显示,滚动条只有在鼠标在其上方的时候才会显示。

    希望对你有所帮助


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2013年11月7日 6:24
    版主
  • Hi KK0603,

    刚测了下你的代码,的确有类似问题出现,不过我对UserControl设置了CacheMode为BitmapCache之后,就可以不论何时都能显示ScrollBar,你可以测试一下。请参考http://msdn.microsoft.com/zh-cn/library/windows/apps/windows.ui.xaml.uielement.cachemode.aspx

    以上请参考。

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    2013年11月8日 16:08
    版主
  • 试了James的方法,把CacheMode设成BitmapCache之后问题解决.

    之前还试过重写ScrollViewer的样式,把NoIndicator的VirtualState删除后,一旦鼠标或触电出现在ScrollViewer上,滚动条就会一直显示了.

    2013年11月18日 0:52
  • 如果 ScrollViewer 里面是 WebView 的话,把CacheMode设成BitmapCache之后,WebView 变黑,无法显示。
    2015年8月28日 9:29