ShellPage.xaml.cs
 1  // Copyright (c) Microsoft Corporation
 2  // The Microsoft Corporation licenses this file to you under the MIT license.
 3  // See the LICENSE file in the project root for more information.
 4  
 5  using Microsoft.PowerToys.QuickAccess.Services;
 6  using Microsoft.PowerToys.QuickAccess.ViewModels;
 7  using Microsoft.UI.Xaml;
 8  using Microsoft.UI.Xaml.Controls;
 9  using Microsoft.UI.Xaml.Media.Animation;
10  
11  namespace Microsoft.PowerToys.QuickAccess.Flyout;
12  
13  /// <summary>
14  /// Hosts the flyout navigation frame.
15  /// </summary>
16  public sealed partial class ShellPage : Page
17  {
18      private LauncherViewModel? _launcherViewModel;
19      private AllAppsViewModel? _allAppsViewModel;
20      private IQuickAccessCoordinator? _coordinator;
21  
22      public ShellPage()
23      {
24          InitializeComponent();
25      }
26  
27      public void Initialize(IQuickAccessCoordinator coordinator, LauncherViewModel launcherViewModel, AllAppsViewModel allAppsViewModel)
28      {
29          _coordinator = coordinator;
30          _launcherViewModel = launcherViewModel;
31          _allAppsViewModel = allAppsViewModel;
32      }
33  
34      private void Page_Loaded(object sender, RoutedEventArgs e)
35      {
36          if (_launcherViewModel == null || _allAppsViewModel == null || _coordinator == null)
37          {
38              return;
39          }
40  
41          if (ContentFrame.Content is LaunchPage)
42          {
43              return;
44          }
45  
46          var context = new FlyoutNavigationContext(_launcherViewModel, _allAppsViewModel, _coordinator);
47          ContentFrame.Navigate(typeof(LaunchPage), context, new SuppressNavigationTransitionInfo());
48      }
49  
50      internal void NavigateToLaunch()
51      {
52          if (_launcherViewModel == null || _allAppsViewModel == null || _coordinator == null)
53          {
54              return;
55          }
56  
57          var context = new FlyoutNavigationContext(_launcherViewModel, _allAppsViewModel, _coordinator);
58          ContentFrame.Navigate(typeof(LaunchPage), context, new SlideNavigationTransitionInfo { Effect = SlideNavigationTransitionEffect.FromLeft });
59      }
60  
61      internal void RefreshIfAppsList()
62      {
63          if (ContentFrame.Content is AppsListPage appsListPage)
64          {
65              appsListPage.ViewModel?.RefreshSettings();
66          }
67      }
68  }