我一直在搜索Google的问题,但没有一个论坛能够提供答案。我只是想在gridview被选中后改变项目的背景颜色。我有一个样式定义在我的App.xaml,我认为这与我的ItemContainerStyle这样的:Windows应用商店 - 所选商品的Gridview背景颜色
<GridView x:Name="gvwTests" Grid.Row="1" HorizontalAlignment="Left" VerticalAlignment="Top"
Width="998" Height="567" Margin="10,51,0,0" Padding="5,0,5,0"
Background="#FF768E9C"
ItemTemplate="{StaticResource testTemplate}"
Style="{StaticResource PAGridViewStyle}" ItemContainerStyle="{StaticResource PAGridViewItemStyle}"
IsDoubleTapEnabled="False" IsRightTapEnabled="False" SelectionMode="Multiple" SelectionChanged="GvwTests_SelectionChanged">
</GridView>
我生成的默认样式的副本:
<Style x:Key="PAGridViewItemStyle" TargetType="GridViewItem">
<Setter Property="Background" Value="#0077FF" />
<Setter Property="Margin" Value="0 0 5 5"/>
<Setter Property="Padding" Value="20 40 40 40" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="GridViewItem">
<Border x:Name="OuterContainer">
...
<VisualStateManager.VisualStateGroups>
...
<VisualStateGroup x:Name="SelectionStates">
<VisualState x:Name="Selecting">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="SelectionBackground"
Storyboard.TargetProperty="Opacity"
Duration="0"
To="1" />
<DoubleAnimation Storyboard.TargetName="SelectedBorder"
Storyboard.TargetProperty="Opacity"
Duration="0"
To="1" />
<DoubleAnimation Storyboard.TargetName="SelectingGlyph"
Storyboard.TargetProperty="Opacity"
Duration="0"
To="1" />
<DoubleAnimation Storyboard.TargetName="HintGlyphBorder"
Storyboard.TargetProperty="Opacity"
Duration="0"
To="1" />
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="contentPresenter"
Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ListViewItemSelectedForegroundThemeBrush}" />
</ObjectAnimationUsingKeyFrames>
<ColorAnimation Storyboard.TargetName="SelectionBackground"
Storyboard.TargetProperty="Color"
Duration="0:0:1"
From="Red" To="Beige" />
</Storyboard>
</VisualState>
...
</VisualStateGroup>
...
</VisualStateManager.VisualStateGroups>
...
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
我不是专家,这使当点击或点击项目时,我无法改变颜色。
我应该怎么做,或者我做错了什么?
如果我理解正确,你重写默认画笔?这是天才,愚蠢的我!在buti出现错误之前,我试过类似这样的资源字典需要一个x键:/我会在明天尝试,我会尽快回复您。谢谢! – DerpyNerd
好吧,我试过了,但我得到一个错误提醒我,资源字典需要一个密钥。我随机添加一个(x:Key =“ListStyles”)。任何想法为什么这些风格不适用? – DerpyNerd
尝试删除您的样式。默认样式位于:C:\ Program Files文件(x86)\ Windows工具包\ 8.0 \ Include \ WinRT \ Xaml \ Design \ generic.xaml – crea7or