Xaml 更新NavigationView中SelectionIndicator的颜色
我正在使用Xaml 更新NavigationView中SelectionIndicator的颜色,xaml,uwp,uwp-xaml,Xaml,Uwp,Uwp Xaml,我正在使用NavigationView控件在我的UWP应用程序中提供左窗格汉堡菜单导航 我想更改选择指示器(显示在所选项目旁边的小矩形)的颜色 在generic.xaml中,我可以看到颜色被设置为系统强调色: <Style TargetType="NavigationViewItem"> <Setter Property="Template"> <Setter.Value> <ControlTemplate
NavigationView
控件在我的UWP应用程序中提供左窗格汉堡菜单导航
我想更改选择指示器(显示在所选项目旁边的小矩形)的颜色
在generic.xaml
中,我可以看到颜色被设置为系统强调色:
<Style TargetType="NavigationViewItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="NavigationViewItem">
<Grid
x:Name="LayoutRoot"
Height="40"
Background="{TemplateBinding Background}"
Control.IsTemplateFocusTarget="True">
<!-- Wrap SelectionIndicator in a grid so that its offset is 0,0 - this enables the offset animation. -->
<Grid
HorizontalAlignment="Left"
VerticalAlignment="Center">
<Rectangle
x:Name="SelectionIndicator"
Width="6"
Height="24"
Fill="{ThemeResource NavigationViewSelectionIndicatorForeground}"
Opacity="0.0"/>
</Grid>
<Border
x:Name="RevealBorder"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}" />
<Grid Height="40" HorizontalAlignment="Left">
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="IconColumn" Width="48" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Viewbox x:Name="IconBox"
Child="{TemplateBinding Icon}"
Margin="16,12"/>
<ContentPresenter x:Name="ContentPresenter"
Grid.Column="1"
ContentTransitions="{TemplateBinding ContentTransitions}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Content="{TemplateBinding Content}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Margin="{TemplateBinding Padding}"/>
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
在我的页面XAML文件(使用NavigationView)中是否有方法将矩形的颜色从NavigationViewSelectionIndicator Foreground
更改为我设置的某个值
我知道我可以复制整个模板并更新副本,并在
导航视图上设置模板,但仅仅更改一个值似乎会带来很大的开销。您可以使用x:Key=“NavigationViewSelectionIndicatorForeground”
定义自己的画笔,例如在App.xaml
:
<Application ...>
<Application.Resources>
<SolidColorBrush x:Key="NavigationViewSelectionIndicatorForeground"
Color="Yellow" />
</Application.Resources>
</Application>
或者,您也可以在页面
的范围内声明资源,甚至在导航视图
的资源
中声明资源,它只需要位于指向导航视图
的XAML树中的路径中
由于您的资源在级联中的时间较晚,因此它将使用您定义的画笔覆盖默认的NavigationViewSelectionIndicatorForeground
。您可以使用x:Key=“NavigationViewSelectionIndicatorForeground”
定义自己的画笔,例如在App.xaml
中:
<Application ...>
<Application.Resources>
<SolidColorBrush x:Key="NavigationViewSelectionIndicatorForeground"
Color="Yellow" />
</Application.Resources>
</Application>
或者,您也可以在页面
的范围内声明资源,甚至在导航视图
的资源
中声明资源,它只需要位于指向导航视图
的XAML树中的路径中
由于您的资源稍后会进入级联,因此它将使用您定义的笔刷覆盖默认的NavigationViewSelectionIndicator Foreground