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

时间:2016-09-15 14:01:23

标签: wpf xaml uwp uwp-xaml

我想设置我的GridviewItem PointerOverBackground和SelectedPointerOverBackground背景颜色。问题是,当我使用默认复选框进行选择时,背景变为黑色/透明,只有边框可见。 Example

<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”从“Inline”设置为“Overlay”时,我得到了这个:Example

我发现无法以“内联”模式填充背景,所以我该如何实现?

1 个答案:

答案 0 :(得分:0)

我通过将“GridViewItemExpanded”样式复制到我的项目中解决了我的问题:

C:\ Program Files(x86)\ Windows Kits \ 10 \ DesignTime \ CommonConfiguration \ Neutral \ UAP \ 10.0.14393.0 \ Generic \ generic.xaml

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