WIn_RustTools/RustTools/ViewModels/ShellViewModel.cs

58 lines
1.3 KiB
C#
Raw Normal View History

2024-07-14 11:24:10 +00:00
using CommunityToolkit.Mvvm.ComponentModel;
using Microsoft.UI.Xaml.Navigation;
using RustTools.Contracts.Services;
2024-08-22 23:59:16 +00:00
using RustTools.muqing;
2024-07-14 11:24:10 +00:00
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)
{
2024-08-17 23:27:24 +00:00
2024-08-22 23:59:16 +00:00
GC.Collect();
2024-07-14 11:24:10 +00:00
IsBackEnabled = NavigationService.CanGoBack;
if (e.SourcePageType == typeof(SettingsPage))
{
Selected = NavigationViewService.SettingsItem;
return;
}
var selectedItem = NavigationViewService.GetSelectedItem(e.SourcePageType);
if (selectedItem != null)
{
Selected = selectedItem;
}
2024-08-22 23:59:16 +00:00
else
{
Selected = null;
}
2024-07-14 11:24:10 +00:00
}
}