Skip to content

Commit b4c0e72

Browse files
committed
Navigate to second (top) NavigationView level
Navigate to the second (top) NavigationView level on app launch, as indicated by the LaunchPageOption setting, and applicable for the music and video library pages.
1 parent afe633f commit b4c0e72

File tree

2 files changed

+44
-8
lines changed

2 files changed

+44
-8
lines changed

Screenbox/Pages/MusicPage.xaml.cs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
#nullable enable
22

3-
using CommunityToolkit.Mvvm.DependencyInjection;
4-
using Screenbox.Core;
5-
using Screenbox.Core.ViewModels;
63
using System;
74
using System.Collections.Generic;
85
using System.Linq;
6+
using CommunityToolkit.Mvvm.DependencyInjection;
7+
using Screenbox.Core;
8+
using Screenbox.Core.Services;
9+
using Screenbox.Core.ViewModels;
10+
using Screenbox.Helpers;
911
using Windows.UI.Xaml.Controls;
1012
using Windows.UI.Xaml.Media.Animation;
1113
using Windows.UI.Xaml.Navigation;
1214
using NavigationView = Microsoft.UI.Xaml.Controls.NavigationView;
1315
using NavigationViewSelectionChangedEventArgs = Microsoft.UI.Xaml.Controls.NavigationViewSelectionChangedEventArgs;
16+
using muxc = Microsoft.UI.Xaml.Controls;
1417

1518
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
1619

@@ -31,6 +34,8 @@ public sealed partial class MusicPage : Page, IContentFrame
3134

3235
private readonly Dictionary<string, Type> _pages;
3336

37+
private ISettingsService Settings => Ioc.Default.GetRequiredService<ISettingsService>();
38+
3439
public MusicPage()
3540
{
3641
this.InitializeComponent();
@@ -55,7 +60,20 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
5560
}
5661
else
5762
{
58-
LibraryNavView.SelectedItem = LibraryNavView.MenuItems[0];
63+
muxc.NavigationViewItem? libraryNavItem = null;
64+
var launchPage = Settings.LaunchPage;
65+
if (launchPage.GetNavPageFirstLevel() != "music")
66+
{
67+
libraryNavItem = (muxc.NavigationViewItem?)LibraryNavView.MenuItems[0];
68+
}
69+
else
70+
{
71+
var launchPageTag = launchPage.GetNavPageSecondLevel();
72+
libraryNavItem = LibraryNavView.MenuItems
73+
.OfType<muxc.NavigationViewItem>()
74+
.FirstOrDefault(item => item.Tag?.ToString() == launchPageTag);
75+
}
76+
LibraryNavView.SelectedItem = libraryNavItem ?? LibraryNavView.MenuItems[0];
5977
}
6078

6179
ViewModel.UpdateSongs();

Screenbox/Pages/VideosPage.xaml.cs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
#nullable enable
22

3-
using CommunityToolkit.Mvvm.DependencyInjection;
4-
using Screenbox.Core;
5-
using Screenbox.Core.ViewModels;
63
using System;
74
using System.Collections.Generic;
85
using System.Linq;
6+
using CommunityToolkit.Mvvm.DependencyInjection;
7+
using Screenbox.Core;
8+
using Screenbox.Core.Services;
9+
using Screenbox.Core.ViewModels;
10+
using Screenbox.Helpers;
911
using Windows.UI.Xaml.Controls;
1012
using Windows.UI.Xaml.Media.Animation;
1113
using Windows.UI.Xaml.Navigation;
1214
using NavigationView = Microsoft.UI.Xaml.Controls.NavigationView;
1315
using NavigationViewSelectionChangedEventArgs = Microsoft.UI.Xaml.Controls.NavigationViewSelectionChangedEventArgs;
16+
using muxc = Microsoft.UI.Xaml.Controls;
1417

1518
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
1619

@@ -33,6 +36,8 @@ public sealed partial class VideosPage : Page, IContentFrame
3336

3437
private readonly Dictionary<string, Type> _pages;
3538

39+
private ISettingsService Settings => Ioc.Default.GetRequiredService<ISettingsService>();
40+
3641
public VideosPage()
3742
{
3843
this.InitializeComponent();
@@ -56,7 +61,20 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
5661
}
5762
else
5863
{
59-
LibraryNavView.SelectedItem = LibraryNavView.MenuItems[0];
64+
muxc.NavigationViewItem? libraryNavItem = null;
65+
var launchPage = Settings.LaunchPage;
66+
if (launchPage.GetNavPageFirstLevel() != "videos")
67+
{
68+
libraryNavItem = (muxc.NavigationViewItem?)LibraryNavView.MenuItems[0];
69+
}
70+
else
71+
{
72+
var launchPageTag = launchPage.GetNavPageSecondLevel();
73+
libraryNavItem = LibraryNavView.MenuItems
74+
.OfType<muxc.NavigationViewItem>()
75+
.FirstOrDefault(item => item.Tag?.ToString() == launchPageTag);
76+
}
77+
LibraryNavView.SelectedItem = libraryNavItem ?? LibraryNavView.MenuItems[0];
6078
}
6179

6280
ViewModel.UpdateVideos();

0 commit comments

Comments
 (0)