Jes*_*sse 3 scrollbar longlistselector windows-phone-8
我正在使用LongListSelector,右侧的滚动条增加了一些空白空间,这使设计变得混乱,所以我想隐藏它.我尝试过以下方法:
ScrollBar sb = ((FrameworkElement)VisualTreeHelper.GetChild(FileList, 0))
.FindName("VerticalScrollBar") as ScrollBar;
sb.Width = 0;
Run Code Online (Sandbox Code Playgroud)
但是这不适用于wp8,我可以使宽度更大但不小.它具有ScrollViewer.VerticalScrollBarVisibility属性,但将其更改为Hidden或Disabled不会执行任何操作.
/编辑:
这似乎有效:
var sb = ((FrameworkElement) VisualTreeHelper.GetChild(FileList, 0))
.FindName("VerticalScrollBar") as ScrollBar;
sb.Margin = new Thickness(-10, 0, 0, 0);
Run Code Online (Sandbox Code Playgroud)
但如果有人有一个更清洁的方法,我仍然希望听到它.
您可以通过重新整理整个控件来解决此问题.
添加此资源:
<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>
Run Code Online (Sandbox Code Playgroud)
使用资源
<phone:LongListSelector Style="{StaticResource LongListSelectorWithNoScrollBarStyle}">
....
</phone:LongListSelector>
Run Code Online (Sandbox Code Playgroud)
瞧.没有滚动条.
| 归档时间: |
|
| 查看次数: |
1267 次 |
| 最近记录: |