Navigationview 为 UWP 应用程序中的子菜单项设置 SelectedItem

Navigationview Set SelectedItem for sub-menu item in UWP app

我试图通过

为导航视图设置默认 selected 项目
DashboardMenuItem.IsExpanded = true;
 Microsoft.UI.Xaml.Controls.NavigationViewItem selectedItem =(Microsoft.UI.Xaml.Controls.NavigationViewItem)DashboardMenuItem.MenuItems[0];
NavView.SelectedItem = selectedItem;

这是我的 XAML

<MUXC:NavigationView.MenuItems>
                <MUXC:NavigationViewItem
                    x:Name="DashboardMenuItem"
                    Content="{x:Bind DashboardLabel}"
                    Foreground="#FFFFFF"
                    ToolTipService.ToolTip="{x:Bind DashboardLabel}">
                    <MUXC:NavigationViewItem.Icon>
                        <FontIcon FontFamily="Segoe MDL2 Assets" Glyph="&#xE8A9;" />
                    </MUXC:NavigationViewItem.Icon>
                    <MUXC:NavigationViewItem.MenuItems>
                        <MUXC:NavigationViewItem
                            x:Name="ListofPersonMenuItem"
                            Content="{x:Bind ListofPersonLabel}"
                            Foreground="#FFFFFF"
                            ToolTipService.ToolTip="{x:Bind ListofPersonLabel}" />
                        <MUXC:NavigationViewItem
                            x:Name="ListofDiedPersonsMenuItem"
                            Content="{x:Bind ListofDiedPersonsLabel}"
                            Foreground="#FFFFFF"
                            ToolTipService.ToolTip="{x:Bind ListofDiedPersonsLabel}" />
                    </MUXC:NavigationViewItem.MenuItems>
                </MUXC:NavigationViewItem>

但是我的菜单项只有高亮背景,仍然没有像我们 select 单击时那样的左侧栏。下面的图片 link(对不起,因为我还不能 post 图片)

https://i.gyazo.com/f2953c8f092534ea26ceb7fef0120de2.png

那么,请问您对此有什么建议吗?

提前致谢

Navigationview Set SelectedItem for sub-menu item in UWP app

在测试期间,问题是展开动画块 select 使项目指示器消失的动画。目前我们有一个解决方法,即在设置 SelectedItem 之前添加任务延迟。它会在 DashboardMenuItem 展开后做 select 动画。

DashboardMenuItem.IsExpanded = true;
Microsoft.UI.Xaml.Controls.NavigationViewItem selectedItem = (Microsoft.UI.Xaml.Controls.NavigationViewItem)DashboardMenuItem.MenuItems[0];
await Task.Delay(100);
MainNavigation.SelectedItem = selectedItem;