silverlight – 在Windows Phone 7上更改ListBox的滚动条颜色

silverlight – 在Windows Phone 7上更改ListBox的滚动条颜色,第1张

概述我有一个< ListBox>具有白色背景的项目,我想更改滚动条颜色,以便在用户滚动项目时可以看到它们. 我怎样才能做到这一点? 您可以更改滚动状态的VisualState.您想编辑ListBox的ScrollViewer的VerticalScrollBar模板.例如,此样式为100%不透明度和红色: <Style x:Key="ScrollViewerStyle1" TargetType="Scr 我有一个< ListBox>具有白色背景的项目,我想更改滚动条颜色,以便在用户滚动项目时可以看到它们.

我怎样才能做到这一点?

解决方法 您可以更改滚动状态的VisualState.您想编辑ListBox的ScrollVIEwer的VerticalScrollbar模板.例如,此样式为100%不透明度和红色:

@H_419_19@<Style x:Key="ScrollVIEwerStyle1" targettype="ScrollVIEwer"> <Setter Property="VerticalScrollbarVisibility" Value="auto"/> <Setter Property="HorizontalScrollbarVisibility" Value="Disabled"/> <Setter Property="Background" Value="transparent"/> <Setter Property="padding" Value="0"/> <Setter Property="borderThickness" Value="0"/> <Setter Property="borderBrush" Value="transparent"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate targettype="ScrollVIEwer"> <border borderBrush="{TemplateBinding borderBrush}" borderThickness="{TemplateBinding borderThickness}" Background="{TemplateBinding Background}"> <visualstatemanager.VisualStateGroups> <VisualStateGroup x:name="ScrollStates"> <VisualStateGroup.Transitions> <VisualTransition GeneratedDuration="00:00:00.5"/> </VisualStateGroup.Transitions> <VisualState x:name="Scrolling"> <Storyboard> <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.Targetname="VerticalScrollbar"/> <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.Targetname="HorizontalScrollbar"/> </Storyboard> </VisualState> <VisualState x:name="NotScrolling"/> </VisualStateGroup> </visualstatemanager.VisualStateGroups> <GrID margin="{TemplateBinding padding}"> <ScrollContentPresenter x:name="ScrollContentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}"/> <Scrollbar x:name="VerticalScrollbar" HorizontalAlignment="Right" Height="auto" IsHitTestVisible="False" IsTabStop="False" Maximum="{TemplateBinding ScrollableHeight}" Minimum="0" Opacity="0" OrIEntation="Vertical" Visibility="{TemplateBinding ComputedVerticalScrollbarVisibility}" Value="{TemplateBinding VerticalOffset}" VIEwportSize="{TemplateBinding VIEwportHeight}" VerticalAlignment="Stretch" WIDth="5" Background="Red"/> <Scrollbar x:name="HorizontalScrollbar" HorizontalAlignment="Stretch" Height="5" IsHitTestVisible="False" IsTabStop="False" Maximum="{TemplateBinding ScrollableWIDth}" Minimum="0" Opacity="0" OrIEntation="Horizontal" Visibility="{TemplateBinding ComputedHorizontalScrollbarVisibility}" Value="{TemplateBinding HorizontalOffset}" VIEwportSize="{TemplateBinding VIEwportWIDth}" VerticalAlignment="Bottom" WIDth="auto"/> </GrID> </border> </ControlTemplate> </Setter.Value> </Setter> </Style>

ListBox的样式(使用上面的VerticalScrollbar模板)是这样的:

@H_419_19@<Style x:Key="ListBoxStyle1" targettype="ListBox"> <Setter Property="Background" Value="transparent"/> <Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/> <Setter Property="ScrollVIEwer.HorizontalScrollbarVisibility" Value="Disabled"/> <Setter Property="ScrollVIEwer.VerticalScrollbarVisibility" Value="auto"/> <Setter Property="borderThickness" Value="0"/> <Setter Property="borderBrush" Value="transparent"/> <Setter Property="padding" Value="0"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate targettype="ListBox"> <ScrollVIEwer x:name="ScrollVIEwer" borderBrush="{TemplateBinding borderBrush}" borderThickness="{TemplateBinding borderThickness}" Background="{TemplateBinding Background}" Foreground="{TemplateBinding Foreground}" padding="{TemplateBinding padding}" Style="{StaticResource ScrollVIEwerStyle1}" > <ItemsPresenter/> </ScrollVIEwer> </ControlTemplate> </Setter.Value> </Setter> </Style>

您可以使用Expression Blend来制作XAML,因为它更有效.

总结

以上是内存溢出为你收集整理的silverlight – 在Windows Phone 7上更改ListBox的滚动条颜色全部内容,希望文章能够帮你解决silverlight – 在Windows Phone 7上更改ListBox的滚动条颜色所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1000886.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存