如何更改SplitView窗格UWP中的选择颜色?

时间:2018-03-27 21:08:07

标签: c# xaml uwp uwp-xaml

我需要你的帮助。 我正在开发一个UWP应用程序。现在我在汉堡菜单上工作,当我选择一个菜单项时,它标有system accent color。我想制作像this这样的选择样式 - 菜单项附近的一个小矩形或至少改变选择颜色。但不幸的是,实际上没有任何信息可以帮助我。既不在StackOverflow上,也不在其他地方。 所以,请帮帮我。并提前感谢。 这是我的一部分代码:

<SplitView Name="menu" Grid.Row="1" OpenPaneLength="250" CompactPaneLength="50" DisplayMode="CompactInline" PaneClosed="menu_PaneClosed">
        <SplitView.Pane>
            <RelativePanel>
                <ListBox>
                    <ListBoxItem Name="homeMenu" IsSelected="True">
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Style="{StaticResource ItemIcon}" Text="&#xE10F;"/>
                            <TextBlock Style="{StaticResource MenuItem}" Text="Home"/>
                        </StackPanel>
                    </ListBoxItem>
                    <ListBoxItem Name="gamingMenu">
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Style="{StaticResource ItemIcon}" Text="&#xE7FC;"/>
                            <TextBlock Style="{StaticResource MenuItem}"  Text="Gaming"/>
                        </StackPanel>
                    </ListBoxItem>
                    <ListBoxItem Name="historyMenu">
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Style="{StaticResource ItemIcon}" Text="&#xE81C;"/>
                            <TextBlock Style="{StaticResource MenuItem}"  Text="History"/>
                        </StackPanel>
                    </ListBoxItem>
                    <ListBoxItem Name="likedMenu">
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Style="{StaticResource ItemIcon}" Text="&#xE19F;"/>
                            <TextBlock Style="{StaticResource MenuItem}"  Text="Liked videos"/>
                        </StackPanel>
                    </ListBoxItem>
                    <ListBoxItem Name="watchLaterMenu">
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Style="{StaticResource ItemIcon}" Text="&#xE121;"/>
                            <TextBlock Style="{StaticResource MenuItem}"  Text="Watch later"/>
                        </StackPanel>
                    </ListBoxItem>
                </ListBox>
            </RelativePanel>
        </SplitView.Pane>
        <SplitView.Content>
            <Frame Name="content"/>
        </SplitView.Content>
    </SplitView>

1 个答案:

答案 0 :(得分:1)

我建议您可以使用python3-core.bbappend控件而不是ListBox。你会得到同样的效果。然后编辑ListViewItem styles and templates。你可以看到里面有一个ListView。您可以根据需要更改它。

例如,

SelectedBackground="{ThemeResource SystemControlHighlightListAccentLowBrush}"
<Page.Resources>
    <Style x:Key="ListViewItemContainerStyle1" TargetType="ListViewItem">
        <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
        <Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" />
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="Foreground" Value="{ThemeResource SystemControlForegroundBaseHighBrush}" />
        <Setter Property="TabNavigation" Value="Local"/>
        <Setter Property="IsHoldingEnabled" Value="True"/>
        <Setter Property="Padding" Value="12,0,12,0"/>
        <Setter Property="HorizontalContentAlignment" Value="Left"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="MinWidth" Value="{ThemeResource ListViewItemMinWidth}"/>
        <Setter Property="MinHeight" Value="{ThemeResource ListViewItemMinHeight}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListViewItem">
                    <ListViewItemPresenter
      ContentTransitions="{TemplateBinding ContentTransitions}"
      SelectionCheckMarkVisualEnabled="True"
      CheckBrush="{ThemeResource SystemControlForegroundBaseMediumHighBrush}"
      CheckBoxBrush="{ThemeResource SystemControlForegroundBaseMediumHighBrush}"
      DragBackground="{ThemeResource ListViewItemDragBackgroundThemeBrush}"
      DragForeground="{ThemeResource ListViewItemDragForegroundThemeBrush}"
      FocusBorderBrush="{ThemeResource SystemControlForegroundAltHighBrush}"
      FocusSecondaryBorderBrush="{ThemeResource SystemControlForegroundBaseHighBrush}"
      PlaceholderBackground="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}"
      PointerOverBackground="{ThemeResource SystemControlHighlightListLowBrush}"
      PointerOverForeground="{ThemeResource SystemControlHighlightAltBaseHighBrush}"
      SelectedBackground="Red"
      SelectedForeground="{ThemeResource SystemControlHighlightAltBaseHighBrush}"
      SelectedPointerOverBackground="{ThemeResource SystemControlHighlightListAccentMediumBrush}"
      PressedBackground="{ThemeResource SystemControlHighlightListMediumBrush}"
      SelectedPressedBackground="{ThemeResource SystemControlHighlightListAccentHighBrush}"
      DisabledOpacity="{ThemeResource ListViewItemDisabledThemeOpacity}"
      DragOpacity="{ThemeResource ListViewItemDragThemeOpacity}"
      ReorderHintOffset="{ThemeResource ListViewItemReorderHintThemeOffset}"
      HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
      VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
      ContentMargin="{TemplateBinding Padding}"
      CheckMode="Inline"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</Page.Resources>