mirror of
https://github.com/PacktPublishing/Learn-WinUI-3-Second-Edition.git
synced 2026-06-20 12:23:09 +00:00
Add chapter 10 sample project
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user