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

View File

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

View File

@@ -108,10 +108,14 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{ {
var item = navigationView.MenuItems var item = navigationView.MenuItems
.OfType<NavigationViewItem>() .OfType<NavigationViewItem>()
.First(menuItem => (string)menuItem.Content == (string)args.InvokedItem); .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; var pageType = item.GetValue(NavHelper.NavigateToProperty) as Type;
NavigationService.Navigate(pageType); NavigationService.Navigate(pageType);
} }
}
private void OnBackRequested(NavigationView sender, NavigationViewBackRequestedEventArgs args) private void OnBackRequested(NavigationView sender, NavigationViewBackRequestedEventArgs args)
{ {