单击菜单项后,MAUI Shell 会在其左侧显示一条蓝色垂直线。它还会将背景颜色更改为稍微暗一些。我想禁用该视觉指示。
我确实尝试过覆盖 FlyoutContent,这确实有效,但后来我不得不重新发明整个 FlyoutContentTemplate 只是为了解决这一问题。
更改 FlyoutItems 的模板不起作用。所选项目的样式似乎不是 FlyoutItemTemplate 的一部分。
更改 FlyoutItems 的样式也不起作用。
根据这篇文章,看起来有一个名为 Selected 的视觉状态导致了这种情况。我想完全消除这种视觉状态,这样就没有所选项目的视觉指示。有办法做到吗?
感谢您的任何指点或想法!
更新:
该问题仅出现在 Windows 平台上。看起来 MAUI 使用 NavigationView 来渲染 Shell,并且 WinUI NavigationViewItem 确实有办法禁用可选择性。
所以也许我要问的问题是是否有一种方法可以覆盖 Windows 平台上 MAUI Shell 的渲染,以便 MenuItem 将 WinUI NavigationViewItem 的 SelectsOnInvoked 属性设置为 false?
如果要删除 .NET MAUI Shell 中菜单项左侧的蓝色垂直线,您可以覆盖并将
NavigationViewSelectionIndicatorForeground
设置为 Color="transparent"
。
请在Platforms/Windows/App.xaml中添加以下代码:
<maui:MauiWinUIApplication
x:Class="ShellFlyoutSample.WinUI.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:maui="using:Microsoft.Maui"
xmlns:local="using:ShellFlyoutSample.WinUI">
<maui:MauiWinUIApplication.Resources>
<StaticResource x:Key="NavigationViewSelectionIndicatorForeground" ResourceKey="SystemControlForegroundAccentBrush" />
<SolidColorBrush x:Key="SystemControlForegroundAccentBrush" Color="transparent" />
</maui:MauiWinUIApplication.Resources>
</maui:MauiWinUIApplication>
输出: