如何使用选择复选框来设置GridView项目背景的样式?

问题描述:

我想风格我的GridviewItem PointerOverBackground和SelectedPointerOverBackground背景颜色。问题是,当我使用默认复选框进行选择时,背景变为黑色/透明,只有边框可见。 Example如何使用选择复选框来设置GridView项目背景的样式?

<GridView x:Name="PhotostreamList" ItemContainerStyle="{StaticResource GridViewItemContainerStyle}" IsMultiSelectCheckBoxEnabled="{Binding SelectionMode}" SelectionMode="Multiple" ItemsSource="{Binding PhotoList}" SelectionChanged="PhotostreamList_SelectionChanged" HorizontalAlignment="Left" RightTapped="PhotostreamList_RightTapped" > 

我用下面的样式此:

<Style x:Key="GridViewItemContainerStyle" TargetType="GridViewItem"> 
     <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}"/> 
     <Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}"/> 
     <Setter Property="Background" Value="{ThemeResource GridViewItemBackground}"/> 
     <Setter Property="Foreground" Value="{ThemeResource GridViewItemForeground}"/> 
     <Setter Property="TabNavigation" Value="Local"/> 
     <Setter Property="IsHoldingEnabled" Value="True"/> 
     <Setter Property="HorizontalContentAlignment" Value="Center"/> 
     <Setter Property="VerticalContentAlignment" Value="Center"/> 
     <Setter Property="Margin" Value="0,0,4,4"/> 
     <Setter Property="MinWidth" Value="{ThemeResource GridViewItemMinWidth}"/> 
     <Setter Property="MinHeight" Value="{ThemeResource GridViewItemMinHeight}"/> 
     <Setter Property="AllowDrop" Value="False"/> 
     <Setter Property="UseSystemFocusVisuals" Value="True"/> 
     <Setter Property="FocusVisualMargin" Value="-2"/> 
     <Setter Property="FocusVisualPrimaryBrush" Value="{ThemeResource GridViewItemFocusVisualPrimaryBrush}"/> 
     <Setter Property="FocusVisualPrimaryThickness" Value="2"/> 
     <Setter Property="FocusVisualSecondaryBrush" Value="{ThemeResource GridViewItemFocusVisualSecondaryBrush}"/> 
     <Setter Property="FocusVisualSecondaryThickness" Value="1"/> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="GridViewItem"> 
        <ListViewItemPresenter 
         CheckBrush="{ThemeResource GridViewItemCheckBrush}" 
         ContentMargin="{TemplateBinding Padding}" 
         CheckMode="{ThemeResource GridViewItemCheckMode}" 
         ContentTransitions="{TemplateBinding ContentTransitions}" 
         CheckBoxBrush="{ThemeResource GridViewItemCheckBoxBrush}" 
         DragForeground="{ThemeResource GridViewItemDragForeground}" 
         DragOpacity="{ThemeResource ListViewItemDragThemeOpacity}" 
         DragBackground="{ThemeResource GridViewItemDragBackground}" 
         DisabledOpacity="{ThemeResource ListViewItemDisabledThemeOpacity}" 
         Control.IsTemplateFocusTarget="True" 
         PointerOverForeground="{ThemeResource GridViewItemForegroundPointerOver}" 
         PressedBackground="{ThemeResource GridViewItemBackgroundPressed}" 
         PlaceholderBackground="{ThemeResource GridViewItemPlaceholderBackground}" 
         PointerOverBackground="{ThemeResource GridViewItemBackgroundPointerOver}" 
         ReorderHintOffset="{ThemeResource GridViewItemReorderHintThemeOffset}" 
         SelectedPressedBackground="{ThemeResource GridViewItemBackgroundSelectedPressed}" 
         SelectionCheckMarkVisualEnabled="{ThemeResource GridViewItemSelectionCheckMarkVisualEnabled}" 
         SelectedForeground="{ThemeResource GridViewItemForegroundSelected}" 
         SelectedPointerOverBackground="{ThemeResource GridViewItemBackgroundSelectedPointerOver}" 
         SelectedBackground="{ThemeResource GridViewItemBackgroundSelected}" 
         VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" /> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 

是我发现的是,当我设置从“内联”的“CheckMode”为“叠加”我得到这个: Example

我发现没有办法填充“内联”模式的背景,所以我怎么能做到这一点?

C:

我从复制 “GridViewItemExpanded” 风格到我的项目解决我的问题\程序文件(x86)\的Windows套件\ 10 \设计时\ CommonConfiguration \中性\ UAP \ 10.0.14393.0 \通用\ generic.xaml

此样式包含复选框的整个ControlTemplate,我可以对背景进行更改。