在我的App.xaml中,我可以设置以下行,这将更改整个应用程序的ListVIEws的选定颜色.
<SolIDcolorBrush x:Key="ListVIEwItemSelectedBackgroundthemeBrush" color="Orange" />
但是,我想逐页进行,所以我想在页面资源中设置它.
但是,当我尝试这个时,它被忽略了,从未使用过.它似乎只适用于app.xaml.
有谁知道我怎么能绕过这个?
这适用于使用XAML和C#编写的windows 8商店应用程序.
谢谢
解决方法 在visual studio xaml设计器中,您可以进入Outline窗口,单击树中ListVIEw右键,单击Edit Additional Template> Edit Item Container Style> Edit a copy.它将生成ListVIEwItem样式的副本,然后您可以用您想要的任何颜色替换此样式中的ListVIEwItemSelectedBackgroundthemeBrush.
如果只需要更改一种颜色,则可以使用Tag属性作为颜色,如果你有很多不同颜色的页面,你就不必在每个页面中都有整个样式.
这是一个例子:
ListVIEwItem样式使用Tag作为您在App.xaml中定义的选择颜色:
<Style x:Key="TagListVIEwItemStyle" targettype="ListVIEwItem"> <Setter Property="FontFamily" Value="{StaticResource ContentControlthemeFontFamily}"/> <Setter Property="FontSize" Value="{StaticResource ControlContentthemeFontSize}"/> <Setter Property="Background" Value="transparent"/> <Setter Property="TabNavigation" Value="Local"/> <Setter Property="IsHoldingEnabled" Value="True"/> <Setter Property="margin" Value="0,18,2"/> <Setter Property="HorizontalContentAlignment" Value="left"/> <Setter Property="VerticalContentAlignment" Value="top"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate targettype="ListVIEwItem"> <border x:name="OuterContainer"> <visualstatemanager.VisualStateGroups> <VisualStateGroup x:name="CommonStates"> <VisualState x:name="normal"/> <VisualState x:name="PointerOver"> <Storyboard> <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.Targetname="PointerOverborder"/> <!--<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Fill" Storyboard.Targetname="SelectionBackground"> <discreteObjectKeyFrame KeyTime="0" Value="{StaticResource ListVIEwItemSelectedPointerOverBackgroundthemeBrush}"/> </ObjectAnimationUsingKeyFrames>--> <!--<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="stroke" Storyboard.Targetname="Selectedborder"> <discreteObjectKeyFrame KeyTime="0" Value="{StaticResource ListVIEwItemSelectedPointerOverborderthemeBrush}"/> </ObjectAnimationUsingKeyFrames>--> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Fill" Storyboard.Targetname="SelectedEarmark"> <discreteObjectKeyFrame KeyTime="0" Value="{StaticResource ListVIEwItemSelectedPointerOverBackgroundthemeBrush}"/> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> <VisualState x:name="pressed"> <Storyboard> <PointerDownthemeAnimation Targetname="ContentContainer"/> </Storyboard> </VisualState> <VisualState x:name="PointerOverpressed"> <Storyboard> <PointerDownthemeAnimation Targetname="ContentContainer"/> <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.Targetname="PointerOverborder"/> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Fill" Storyboard.Targetname="SelectionBackground"> <discreteObjectKeyFrame KeyTime="0" Value="{StaticResource ListVIEwItemSelectedPointerOverBackgroundthemeBrush}"/> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="stroke" Storyboard.Targetname="Selectedborder"> <discreteObjectKeyFrame KeyTime="0" Value="{StaticResource ListVIEwItemSelectedPointerOverborderthemeBrush}"/> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Fill" Storyboard.Targetname="SelectedEarmark"> <discreteObjectKeyFrame KeyTime="0" Value="{StaticResource ListVIEwItemSelectedPointerOverBackgroundthemeBrush}"/> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> <VisualState x:name="Disabled"> <Storyboard> <DoubleAnimation Duration="0" To="{StaticResource ListVIEwItemDisabledthemeOpacity}" Storyboard.TargetProperty="Opacity" Storyboard.Targetname="contentPresenter"/> </Storyboard> </VisualState> </VisualStateGroup> <VisualStateGroup x:name="Focusstates"> <VisualState x:name="Focused"> <Storyboard> <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.Targetname="FocusVisual"/> </Storyboard> </VisualState> <VisualState x:name="Unfocused"/> <VisualState x:name="PointerFocused"/> </VisualStateGroup> <VisualStateGroup x:name="SelectionHintStates"> <VisualStateGroup.Transitions> <VisualTransition GeneratedDuration="0:0:0.65" To="NoSelectionHint"/> </VisualStateGroup.Transitions> <VisualState x:name="VerticalSelectionHint"> <Storyboard> <SwipeHintthemeAnimation ToHorizontalOffset="0" Targetname="SelectionBackground" ToVerticalOffset="15"/> <SwipeHintthemeAnimation ToHorizontalOffset="0" Targetname="Contentborder" ToVerticalOffset="15"/> <SwipeHintthemeAnimation ToHorizontalOffset="0" Targetname="Selectedborder" ToVerticalOffset="15"/> <SwipeHintthemeAnimation ToHorizontalOffset="0" Targetname="Selectedcheckmark" ToVerticalOffset="15"/> <DoubleAnimationUsingKeyFrames Duration="0:0:0.500" Storyboard.TargetProperty="Opacity" Storyboard.Targetname="HintGlyph"> <discreteDoubleKeyFrame KeyTime="0:0:0" Value="0.5"/> <discreteDoubleKeyFrame KeyTime="0:0:0.500" Value="0"/> </DoubleAnimationUsingKeyFrames> </Storyboard> </VisualState> <VisualState x:name="HorizontalSelectionHint"> <Storyboard> <SwipeHintthemeAnimation ToHorizontalOffset="-23" Targetname="SelectionBackground" ToVerticalOffset="0"/> <SwipeHintthemeAnimation ToHorizontalOffset="-23" Targetname="Contentborder" ToVerticalOffset="0"/> <SwipeHintthemeAnimation ToHorizontalOffset="-23" Targetname="Selectedborder" ToVerticalOffset="0"/> <SwipeHintthemeAnimation ToHorizontalOffset="-23" Targetname="Selectedcheckmark" ToVerticalOffset="0"/> <DoubleAnimationUsingKeyFrames Duration="0:0:0.500" Storyboard.TargetProperty="Opacity" Storyboard.Targetname="HintGlyph"> <discreteDoubleKeyFrame KeyTime="0:0:0" Value="0.5"/> <discreteDoubleKeyFrame KeyTime="0:0:0.500" Value="0"/> </DoubleAnimationUsingKeyFrames> </Storyboard> </VisualState> <VisualState x:name="NoSelectionHint"/> </VisualStateGroup> <VisualStateGroup x:name="SelectionStates"> <VisualState x:name="Unselecting"> <Storyboard> <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.Targetname="HintGlyphborder"/> </Storyboard> </VisualState> <VisualState x:name="Unselected"> <Storyboard> <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.Targetname="HintGlyphborder"/> </Storyboard> </VisualState> <VisualState x:name="UnselectedPointerOver"> <Storyboard> <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.Targetname="HintGlyphborder"/> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.Targetname="contentPresenter"> <discreteObjectKeyFrame KeyTime="0" Value="{StaticResource ListVIEwItemSelectedForegroundthemeBrush}"/> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> <VisualState x:name="UnselectedSwiPing"> <Storyboard> <DoubleAnimation Duration="0" To="0.5" Storyboard.TargetProperty="Opacity" Storyboard.Targetname="SelectingGlyph"/> <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.Targetname="HintGlyphborder"/> </Storyboard> </VisualState> <VisualState x:name="Selecting"> <Storyboard> <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.Targetname="SelectionBackground"/> <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.Targetname="Selectedborder"/> <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.Targetname="SelectingGlyph"/> <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.Targetname="HintGlyphborder"/> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.Targetname="contentPresenter"> <discreteObjectKeyFrame KeyTime="0" Value="{StaticResource ListVIEwItemSelectedForegroundthemeBrush}"/> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> <VisualState x:name="Selected"> <Storyboard> <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.Targetname="SelectionBackground"/> <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.Targetname="Selectedborder"/> <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.Targetname="Selectedcheckmark"/> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.Targetname="contentPresenter"> <discreteObjectKeyFrame KeyTime="0" Value="{StaticResource ListVIEwItemSelectedForegroundthemeBrush}"/> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> <VisualState x:name="SelectedSwiPing"> <Storyboard> <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.Targetname="SelectionBackground"/> <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.Targetname="Selectedborder"/> <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.Targetname="Selectedcheckmark"/> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.Targetname="contentPresenter"> <discreteObjectKeyFrame KeyTime="0" Value="{StaticResource ListVIEwItemSelectedForegroundthemeBrush}"/> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> <VisualState x:name="SelectedUnfocused"> <Storyboard> <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.Targetname="SelectionBackground"/> <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.Targetname="Selectedborder"/> <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.Targetname="Selectedcheckmark"/> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.Targetname="contentPresenter"> <discreteObjectKeyFrame KeyTime="0" Value="{StaticResource ListVIEwItemSelectedForegroundthemeBrush}"/> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> </VisualStateGroup> <VisualStateGroup x:name="DragStates"> <VisualStateGroup.Transitions> <VisualTransition GeneratedDuration="0:0:0.2" To="NotDragging"/> </VisualStateGroup.Transitions> <VisualState x:name="NotDragging"/> <VisualState x:name="Dragging"> <Storyboard> <DoubleAnimation Duration="0" To="{StaticResource ListVIEwItemDragthemeOpacity}" Storyboard.TargetProperty="Opacity" Storyboard.Targetname="InnerDragContent"/> <DragItemthemeAnimation Targetname="InnerDragContent"/> <FadeOutthemeAnimation Targetname="SelectedcheckmarkOuter"/> <FadeOutthemeAnimation Targetname="Selectedborder"/> </Storyboard> </VisualState> <VisualState x:name="DraggingTarget"> <Storyboard> <DropTargetItemthemeAnimation Targetname="OuterContainer"/> </Storyboard> </VisualState> <VisualState x:name="MultipleDraggingPrimary"> <Storyboard> <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.Targetname="MultiArrangeOverlayBackground"/> <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.Targetname="MultiArrangeOverlayText"/> <DoubleAnimation Duration="0" To="{StaticResource ListVIEwItemDragthemeOpacity}" Storyboard.TargetProperty="Opacity" Storyboard.Targetname="Contentborder"/> <FadeInthemeAnimation Targetname="MultiArrangeOverlayBackground"/> <FadeInthemeAnimation Targetname="MultiArrangeOverlayText"/> <DragItemthemeAnimation Targetname="Contentborder"/> <FadeOutthemeAnimation Targetname="SelectionBackground"/> <FadeOutthemeAnimation Targetname="SelectedcheckmarkOuter"/> <FadeOutthemeAnimation Targetname="Selectedborder"/> <FadeOutthemeAnimation Targetname="PointerOverborder"/> </Storyboard> </VisualState> <VisualState x:name="MultipleDraggingSecondary"> <Storyboard> <FadeOutthemeAnimation Targetname="ContentContainer"/> </Storyboard> </VisualState> </VisualStateGroup> <VisualStateGroup x:name="ReorderHintStates"> <VisualStateGroup.Transitions> <VisualTransition GeneratedDuration="0:0:0.2" To="noreorderHint"/> </VisualStateGroup.Transitions> <VisualState x:name="noreorderHint"/> <VisualState x:name="BottomreorderHint"> <Storyboard> <DragOverthemeAnimation Direction="Bottom" ToOffset="{StaticResource ListVIEwItemReorderHintthemeOffset}" Targetname="ReorderHintContent"/> </Storyboard> </VisualState> <VisualState x:name="topReorderHint"> <Storyboard> <DragOverthemeAnimation Direction="top" ToOffset="{StaticResource ListVIEwItemReorderHintthemeOffset}" Targetname="ReorderHintContent"/> </Storyboard> </VisualState> <VisualState x:name="RightReorderHint"> <Storyboard> <DragOverthemeAnimation Direction="Right" ToOffset="{StaticResource ListVIEwItemReorderHintthemeOffset}" Targetname="ReorderHintContent"/> </Storyboard> </VisualState> <VisualState x:name="leftReorderHint"> <Storyboard> <DragOverthemeAnimation Direction="left" ToOffset="{StaticResource ListVIEwItemReorderHintthemeOffset}" Targetname="ReorderHintContent"/> </Storyboard> </VisualState> </VisualStateGroup> <VisualStateGroup x:name="DataVirtualizationStates"> <VisualState x:name="DataAvailable"/> <VisualState x:name="DataPlaceholder"> <Storyboard> <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Visibility" Storyboard.Targetname="PlaceholderTextBlock"> <discreteObjectKeyFrame KeyTime="0"> <discreteObjectKeyFrame.Value> <Visibility>Visible</Visibility> </discreteObjectKeyFrame.Value> </discreteObjectKeyFrame> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Visibility" Storyboard.Targetname="PlaceholderRect"> <discreteObjectKeyFrame KeyTime="0"> <discreteObjectKeyFrame.Value> <Visibility>Visible</Visibility> </discreteObjectKeyFrame.Value> </discreteObjectKeyFrame> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> </VisualStateGroup> </visualstatemanager.VisualStateGroups> <GrID x:name="ReorderHintContent" Background="transparent"> <Path x:name="SelectingGlyph" Data="F1 M133.1,17.9 L137.2,13.2 L144.6,19.6 L156.4,5.8 L161.2,9.9 L145.6,28.4 z" Fill="{StaticResource ListVIEwItemCheckSelectingthemeBrush}" FlowDirection="leftToRight" HorizontalAlignment="Right" Height="13" margin="0,9.5,0" Opacity="0" Stretch="Fill" VerticalAlignment="top" WIDth="15"/> <border x:name="HintGlyphborder" HorizontalAlignment="Right" Height="40" margin="4" Opacity="0" VerticalAlignment="top" WIDth="40"> <Path x:name="HintGlyph" Data="F1 M133.1,28.4 z" Fill="{StaticResource ListVIEwItemCheckHintthemeBrush}" FlowDirection="leftToRight" HorizontalAlignment="Right" Height="13" margin="0,5.5,0" Opacity="0" Stretch="Fill" VerticalAlignment="top" WIDth="15"/> </border> <border x:name="ContentContainer"> <GrID x:name="InnerDragContent"> <Rectangle x:name="PointerOverborder" Fill="{StaticResource ListVIEwItemPointerOverBackgroundthemeBrush}" IsHitTestVisible="False" margin="1" Opacity="0"/> <Rectangle x:name="FocusVisual" IsHitTestVisible="False" Opacity="0" stroke="{StaticResource ListVIEwItemFocusborderthemeBrush}" strokeThickness="2"/> <Rectangle x:name="SelectionBackground" Fill="{TemplateBinding Tag}" margin="4" Opacity="0"/> <border x:name="Contentborder" borderBrush="{TemplateBinding borderBrush}" borderThickness="{TemplateBinding borderThickness}" Background="{TemplateBinding Background}" margin="4"> <GrID> <ContentPresenter x:name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" ContentTransitions="{TemplateBinding ContentTransitions}" Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" margin="{TemplateBinding padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> <TextBlock x:name="PlaceholderTextBlock" Foreground="{x:Null}" IsHitTestVisible="False" margin="{TemplateBinding padding}" Opacity="0" Text="Xg"/> <Rectangle x:name="PlaceholderRect" Fill="{StaticResource ListVIEwItemPlaceholderBackgroundthemeBrush}" IsHitTestVisible="False" Visibility="Collapsed"/> <Rectangle x:name="MultiArrangeOverlayBackground" Fill="{StaticResource ListVIEwItemDragBackgroundthemeBrush}" IsHitTestVisible="False" Opacity="0"/> </GrID> </border> <Rectangle x:name="Selectedborder" IsHitTestVisible="False" margin="4" Opacity="0" stroke="{TemplateBinding Tag}" strokeThickness="{StaticResource ListVIEwItemSelectedborderthemeThickness}"/> <border x:name="SelectedcheckmarkOuter" HorizontalAlignment="Right" IsHitTestVisible="False" margin="4" VerticalAlignment="top"> <GrID x:name="Selectedcheckmark" Height="40" Opacity="0" WIDth="40"> <Path x:name="SelectedEarmark" Data="M0,0 L40,40 z" Fill="{TemplateBinding Tag}" Stretch="Fill"/> <Path Data="F1 M133.1,28.4 z" Fill="{StaticResource ListVIEwItemCheckthemeBrush}" FlowDirection="leftToRight" HorizontalAlignment="Right" Height="13" margin="0,0" Stretch="Fill" VerticalAlignment="top" WIDth="15"/> </GrID> </border> <TextBlock x:name="MultiArrangeOverlayText" Foreground="{StaticResource ListVIEwItemDragForegroundthemeBrush}" FontSize="26.667" FontFamily="{StaticResource ContentControlthemeFontFamily}" IsHitTestVisible="False" margin="18,9,0" Opacity="0" textwrapPing="Wrap" Text="{Binding TemplateSettings.DragItemsCount,relativeSource={relativeSource Mode=TemplatedParent}}" TextTrimming="WordEllipsis"/> </GrID> </border> </GrID> </border> </ControlTemplate> </Setter.Value> </Setter> </Style>
然后在每个页面中,您只需定义一个样式:
<Style x:Key="OrangeListVIEwItemStyle" targettype="ListVIEwItem" BasedOn="{StaticResource TagListVIEwItemStyle}"> <Setter Property="Tag"> <Setter.Value> <SolIDcolorBrush color="Orange"/> </Setter.Value> </Setter> </Style>
如果您需要定义多种颜色,则可以通过添加一些附加属性来使用相同的原则.
总结以上是内存溢出为你收集整理的c# – 在WinRT XAML中更改页面级别ListViewItem的选择颜色全部内容,希望文章能够帮你解决c# – 在WinRT XAML中更改页面级别ListViewItem的选择颜色所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)