【发布时间】:2019-10-29 15:49:18
【问题描述】:
我是 UWP 编码的新手。我有一个使用 VB.NET 的简单 UWP 应用程序。同一“表单”上其他地方的 ContentGrid 后面的代码会更新一些影响 NavigationView 的设置。如何让 NavigationView 刷新?
我似乎无法将它从一个视图引用到另一个视图
导航视图的 XAML 片段:
<winui:NavigationView.MenuItems>
<winui:NavigationViewItem x:Uid="Shell_Main" Name="MainMenu" Tag="" Icon="Home" helpers:NavHelper.NavigateTo="views:MainPage" />
<winui:NavigationViewItem x:Uid="Shell_ContentGrid" Name="Video1" Tag="" Icon="GotoStart" helpers:NavHelper.NavigateTo="views:ContentGridPage" />
<winui:NavigationViewItem x:Uid="Shell_ContentGrid2" Name="Video2" Tag="\KES\" Icon="Slideshow" helpers:NavHelper.NavigateTo="views:ContentGridPage2" />
</winui:NavigationView.MenuItems>
<winui:NavigationView.PaneFooter>
<NavigationViewItem Icon="Help" Content="Help" Tag="User"/>
</winui:NavigationView.PaneFooter>
表单/视图后面的 VB 代码用于禁用 OnLoaded 事件中的菜单项,工作正常
For Each topic In navigationView.MenuItems
strDepends = topic.tag
bAllowed = Helpers.ContentAllowed(strDepends)
If Not bAllowed Then topic.IsEnabled = False
Next
另一个视图上的代码更改了设置,启用了菜单设置,但我似乎无法告诉菜单刷新。
我希望 NavigationView 刷新/重绘/无论什么
【问题讨论】:
-
只是一个小小的挑剔:如果你愿意,你可以使用
topic.IsEnabled = bAllowed或相反的逻辑。现在我看多了,你可能可以直接删掉 bAllowed 除非它在其他地方使用,然后将 topic.IsEnabled 设置为 Helpers.ContentAllowed() 的结果。 -
要添加到@JohnPete22 帖子,可以是一行
topic.IsEnabled = Helpers.ContentAllowed(topic.tag)