52 lines
1.2 KiB
C#
52 lines
1.2 KiB
C#
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
|
using Microsoft.UI.Xaml.Navigation;
|
|
|
|
using RustTools.Contracts.Services;
|
|
using RustTools.Views;
|
|
|
|
namespace RustTools.ViewModels;
|
|
|
|
public partial class ShellViewModel : ObservableRecipient
|
|
{
|
|
[ObservableProperty]
|
|
private bool isBackEnabled;
|
|
|
|
[ObservableProperty]
|
|
private object? selected;
|
|
|
|
public INavigationService NavigationService
|
|
{
|
|
get;
|
|
}
|
|
|
|
public INavigationViewService NavigationViewService
|
|
{
|
|
get;
|
|
}
|
|
|
|
public ShellViewModel(INavigationService navigationService, INavigationViewService navigationViewService)
|
|
{
|
|
NavigationService = navigationService;
|
|
NavigationService.Navigated += OnNavigated;
|
|
NavigationViewService = navigationViewService;
|
|
}
|
|
|
|
private void OnNavigated(object sender, NavigationEventArgs e)
|
|
{
|
|
IsBackEnabled = NavigationService.CanGoBack;
|
|
|
|
if (e.SourcePageType == typeof(SettingsPage))
|
|
{
|
|
Selected = NavigationViewService.SettingsItem;
|
|
return;
|
|
}
|
|
|
|
var selectedItem = NavigationViewService.GetSelectedItem(e.SourcePageType);
|
|
if (selectedItem != null)
|
|
{
|
|
Selected = selectedItem;
|
|
}
|
|
}
|
|
}
|