Add chapter 10 sample project

This commit is contained in:
Alvin Ashcraft
2023-08-13 13:40:04 -04:00
parent f9e4d407b9
commit 90f935f4b2
91 changed files with 4110 additions and 0 deletions
@@ -0,0 +1,51 @@
using CommunityToolkit.Mvvm.ComponentModel;
using Microsoft.UI.Xaml.Navigation;
using TemplateStudioSampleApp.Contracts.Services;
using TemplateStudioSampleApp.Views;
namespace TemplateStudioSampleApp.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;
}
}
}