windows-phone-8 - 在 LongListSelector 中隐藏滚动条

标签 windows-phone-8 scrollbar longlistselector

我正在使用 LongListSelector,右侧的滚动条添加了一些空白,这扰乱了设计,所以我想隐藏它。我尝试过以下方法:

ScrollBar sb = ((FrameworkElement)VisualTreeHelper.GetChild(FileList, 0))
                           .FindName("VerticalScrollBar") as ScrollBar;
sb.Width = 0;

但这不适用于 wp8,我可以使宽度更大但不能更小。它有一个 ScrollViewer.VerticalScrollBarVisibility 属性,但将其更改为隐藏或禁用不会执行任何操作。

/编辑:

这似乎有效:

var sb = ((FrameworkElement) VisualTreeHelper.GetChild(FileList, 0))
.FindName("VerticalScrollBar") as ScrollBar;
sb.Margin = new Thickness(-10, 0, 0, 0);

但如果有人有更干净的方法,我仍然想听听。

最佳答案

您可以通过重新设计整个控件来解决此问题。

添加此资源:

<Style x:Key="LongListSelectorWithNoScrollBarStyle" TargetType="phone:LongListSelector">
    <Setter Property="Background" Value="Transparent"/>
    <Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="phone:LongListSelector">
                <Grid Background="{TemplateBinding Background}" d:DesignWidth="480" d:DesignHeight="800">
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="ScrollStates">
                            <VisualStateGroup.Transitions>
                                <VisualTransition GeneratedDuration="00:00:00.5"/>
                            </VisualStateGroup.Transitions>
                            <VisualState x:Name="Scrolling" />
                            <VisualState x:Name="NotScrolling"/>
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>
                    <Grid Margin="{TemplateBinding Padding}">
                        <ViewportControl x:Name="ViewportControl" HorizontalContentAlignment="Stretch" VerticalAlignment="Top"/>
                    </Grid>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

使用资源

<phone:LongListSelector Style="{StaticResource LongListSelectorWithNoScrollBarStyle}">
    ....
</phone:LongListSelector>

瞧。没有滚动条。

关于windows-phone-8 - 在 LongListSelector 中隐藏滚动条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18414498/

相关文章:

css - 如何在浏览器屏幕缩小时显示水平滚动条

带滚动条的 HTML Canvas

android - 如何在android中使用gridview的水平滚动条?

windows-phone-7 - 如何禁用 Windows Phone 8 键盘按钮?

wpf - 如果绑定(bind)源为空,如何为图像设置默认源?

windows-phone-8 - 在 Windows Phone 8 中执行照片选择器任务或相机捕获任务后,墓碑不起作用

c# - 隔离存储 - 从最后一行到第一行读取文本文件

c# - 获取选择的 Item 的父 ObservableCollection - WP8

canvas - 如何在长列表选择器中设置数据模板的 z 索引

windows-phone-7 - Windows Phone 8 平台上的 GPS 错误行为