NavigationView是自动使用Reveal高亮显示的众多控件之一,它也是Fluent Design System的新组件之一,其目的是为应用程序增光。
@一种。如果我们要处理的控件的共享状态不如NavigationViewItem那样多,那么Milto解决方案就可以工作,但是NavigationMenuItem具有:
不考虑它的禁用状态。只需将前景色属性强制为所需的颜色,即可得到以下内容:
实现目标的最简单解决方案是覆盖NavigationViewItem模板中的资源,您实际上可以在generic.xaml中检出该资源。您可以这样做,例如:
<Grid.Resources>
<SolidColorBrush x:Key="NavigationViewItemForegroundPointerOver" Color="Red"/>
<SolidColorBrush x:Key="NavigationViewItemForegroundSelected" Color="Red"/>
<SolidColorBrush x:Key="NavigationViewItemForegroundSelectedPointerOver" Color="Red"/>
<SolidColorBrush x:Key="NavigationViewItemForegroundPressed" Color="Red"/>
<SolidColorBrush x:Key="NavigationViewItemForegroundSelectedPressed" Color="Red"/>
</Grid.Resources>
Run Code Online (Sandbox Code Playgroud)
如果希望将NavigationViewItem内容的初始状态和图标设置为红色,则必须在标记中进行设置。
这是用于填充NavigationView.MenuItems的项目列表。
<NavigationView.MenuItems>
<NavigationViewItem Icon="AllApps" FontWeight="Bold" Foreground="Red" Content="Apps" Tag="apps"/>
<NavigationViewItem Icon="Video" FontWeight="Bold" Foreground="Red" Content="Games" Tag="games" />
<NavigationViewItem Icon="Audio" FontWeight="Bold" Content="Music" Tag="music"/>
</NavigationView.MenuItems>
Run Code Online (Sandbox Code Playgroud)
结果:
通过此实现,前景与边框/背景是分离的,而边框/背景是负责显示功能特征的其他元素。
您可以修改上面提到的资源管理器以实现自己的UI逻辑,比我们现在正在实现的UI逻辑更“美丽”,甚至可以根据应用程序可能提供的自定义主题,使用绑定在运行时更改主题。
编辑: 要为所有NavigationViewMenuItems(包括Settings)设置Foreground属性,请覆盖以下资源:
<SolidColorBrush x:Key="NavigationViewItemForeground" Color="Red"/>
Run Code Online (Sandbox Code Playgroud)
这样,您无需为所有项目显式设置前景。使用NavigationView的SettingsItem属性,我仅设法更改了图标颜色。
| 归档时间: |
|
| 查看次数: |
1368 次 |
| 最近记录: |