Fix Navigation Footer items crashing the Settings app

This commit is contained in:
Jaime Bernardo 2024-03-05 21:42:02 +00:00
parent 769fbe1161
commit 6ca19a53bb
3 changed files with 26 additions and 20 deletions

View File

@ -225,22 +225,20 @@
Icon="{ui:BitmapIcon Source=/Assets/Settings/Icons/VideoConferenceMute.png}"
IsEnabled="{x:Bind ViewModel.IsVideoConferenceBuild, Mode=OneWay}" />
</NavigationView.MenuItems>
<NavigationView.PaneFooter>
<StackPanel Orientation="Vertical">
<NavigationViewItem
x:Uid="OOBE_NavViewItem"
Icon="{ui:FontIcon Glyph=&#xF133;}"
Tapped="OOBEItem_Tapped" />
<NavigationViewItem
x:Uid="WhatIsNew_NavViewItem"
Icon="{ui:FontIcon Glyph=&#xE789;}"
Tapped="WhatIsNewItem_Tapped" />
<NavigationViewItem
x:Uid="Feedback_NavViewItem"
Icon="{ui:FontIcon Glyph=&#xED15;}"
Tapped="FeedbackItem_Tapped" />
</StackPanel>
</NavigationView.PaneFooter>
<NavigationView.FooterMenuItems>
<NavigationViewItem
x:Uid="OOBE_NavViewItem"
Icon="{ui:FontIcon Glyph=&#xF133;}"
Tapped="OOBEItem_Tapped" />
<NavigationViewItem
x:Uid="WhatIsNew_NavViewItem"
Icon="{ui:FontIcon Glyph=&#xE789;}"
Tapped="WhatIsNewItem_Tapped" />
<NavigationViewItem
x:Uid="Feedback_NavViewItem"
Icon="{ui:FontIcon Glyph=&#xED15;}"
Tapped="FeedbackItem_Tapped" />
</NavigationView.FooterMenuItems>
<i:Interaction.Behaviors>
<ic:EventTriggerBehavior EventName="ItemInvoked">
<ic:InvokeCommandAction Command="{x:Bind ViewModel.ItemInvokedCommand}" />

View File

@ -347,7 +347,11 @@ namespace Microsoft.PowerToys.Settings.UI.Views
if (selectedItem != null)
{
Type pageType = selectedItem.GetValue(NavHelper.NavigateToProperty) as Type;
NavigationService.Navigate(pageType);
if (pageType != null)
{
// pageType might be null because of the navigation bar footer items.
NavigationService.Navigate(pageType);
}
}
}

View File

@ -108,9 +108,13 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
var item = navigationView.MenuItems
.OfType<NavigationViewItem>()
.First(menuItem => (string)menuItem.Content == (string)args.InvokedItem);
var pageType = item.GetValue(NavHelper.NavigateToProperty) as Type;
NavigationService.Navigate(pageType);
.FirstOrDefault(menuItem => (string)menuItem.Content == (string)args.InvokedItem, null);
if (item != null)
{
// item might be null because of the navigation bar footer items.
var pageType = item.GetValue(NavHelper.NavigateToProperty) as Type;
NavigationService.Navigate(pageType);
}
}
private void OnBackRequested(NavigationView sender, NavigationViewBackRequestedEventArgs args)