master
cs 52 lines 1.34 KB
Raw
1 // Copyright (C) Microsoft Corporation. All rights reserved.
2
3 using CommunityToolkit.Mvvm.ComponentModel;
4 using Microsoft.UI.Xaml.Navigation;
5 using WslSettings.Contracts.Services;
6
7 namespace WslSettings.ViewModels;
8
9 public partial class ShellViewModel : ObservableRecipient
10 {
11 private bool isBackEnabled;
12 private object? selected;
13
14 public bool IsBackEnabled
15 {
16 get => isBackEnabled;
17 set => SetProperty(ref isBackEnabled, value);
18 }
19
20 public object? Selected
21 {
22 get => selected;
23 set => SetProperty(ref selected, value);
24 }
25
26 public INavigationService NavigationService
27 {
28 get;
29 }
30
31 public INavigationViewService NavigationViewService
32 {
33 get;
34 }
35
36 public ShellViewModel(INavigationService navigationService, INavigationViewService navigationViewService)
37 {
38 NavigationService = navigationService;
39 NavigationService.Navigated += OnNavigated;
40 NavigationViewService = navigationViewService;
41 }
42
43 private void OnNavigated(object sender, NavigationEventArgs e)
44 {
45 IsBackEnabled = NavigationService.CanGoBack;
46 var selectedItem = NavigationViewService.GetSelectedItem(e.SourcePageType);
47 if (selectedItem != null)
48 {
49 Selected = selectedItem;
50 }
51 }
52 }