Windows phone 8 在LongListSelector中隐藏滚动条

Windows phone 8 在LongListSelector中隐藏滚动条,windows-phone-8,scrollbar,longlistselector,Windows Phone 8,Scrollbar,Longlistselector,我使用了一个LongListSelector,右边的滚动条添加了一点空白,这会弄乱设计,所以我想把它隐藏起来。我尝试了以下方法: ScrollBar sb = ((FrameworkElement)VisualTreeHelper.GetChild(FileList, 0)) .FindName("VerticalScrollBar") as ScrollBar; sb.Width = 0; 但这不适用于wp8,我可以使宽度变大,但不能变小

我使用了一个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>

....

瞧。没有滚动条。

可能重复@caschw它不一样,这就是我发现第一个方法在wp8上不起作用的地方。在对方法和控件层次结构进行深入研究后,没有任何严格的“更干净”的方法。您可以做的唯一更改是将滚动条宽度设置为0,边距设置为新厚度()没有0边距的参数。@lthibodeaux将宽度和边距设置为0不会完全消除空白。当它是阴性的时候,它会发生。我有一个类似的问题。对我来说,有效的方法是将LLS包装到ScrollViewer标记中,并将该标记的VerticalScrollBarVisibility设置为“隐藏”。这很好地实现了效果,但是当我稍后尝试修改最后一个(重新分配它)时,我得到了一个布局周期错误。您的方法适合我,我希望它更干净,但ScrollViewer标记可能会帮助您。我需要在xaml中使用什么导入行才能识别
d:DesignWidth
d:DesignHeight