2013-12-19 63 views
0

我一直在搜索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> 

我不是專家,這使當點擊或點擊項目時,我無法改變顏色。

我應該怎麼做,或者我做錯了什麼?

回答

3

背景顏色更容易在App.xaml中更改爲覆蓋:

<Application.Resources> 
    <ResourceDictionary> 
    <SolidColorBrush x:Key="ListViewItemSelectedPointerOverBackgroundThemeBrush" Color="#56c2ff" /> 
    <SolidColorBrush x:Key="ListViewItemSelectedPointerOverBorderThemeBrush" Color="#56c2ff" /> 
    <SolidColorBrush x:Key="ListViewItemSelectedBackgroundThemeBrush" Color="#56c2ff" /> 
    ... 
+1

如果我理解正確,你重寫默認畫筆?這是天才,愚蠢的我!在buti出現​​錯誤之前,我試過類似這樣的資源字典需要一個x鍵:/我會在明天嘗試,我會盡快回復您。謝謝! – DerpyNerd

+0

好吧,我試過了,但我得到一個錯誤提醒我,資源字典需要一個密鑰。我隨機添加一個(x:Key =「ListStyles」)。任何想法爲什麼這些風格不適用? – DerpyNerd

+0

嘗試刪除您的樣式。默認樣式位於:C:\ Program Files文件(x86)\ Windows工具包\ 8.0 \ Include \ WinRT \ Xaml \ Design \ generic.xaml – crea7or

1

發現麥克Taulty here一個博客,可能的幫助。您使用Blend來更改所有「無法訪問」的樣式。如果你看看XAML Blend生成它實際上更有意義。

+0

嗨,感謝您的輸入:)問題已解決,但我'儘管記住博客,但看起來不錯。 – DerpyNerd

相關問題