using System.Threading.Tasks; using CommunityToolkit.Mvvm.DependencyInjection; using Microsoft.Extensions.DependencyInjection; using StrixMusic.Sdk.ViewModels; using StrixMusic.Sdk.ViewModels.Notifications; using Windows.ApplicationModel.Core; using Windows.UI; using Windows.UI.Core; using Windows.UI.ViewManagement; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; namespace StrixMusic.Sdk.WinUI.Controls.Shells { /// /// A base class for the root control that all shells implement. /// public abstract partial class Shell : UserControl { /// /// Initializes a new instance of the class. /// protected Shell(StrixDataRootViewModel dataRootViewModel) { DataRoot = dataRootViewModel; Loaded += ShellControl_Loaded; // Creating a new instance here so the old Ioc is wiped even if they don't call base.InitServices(); Ioc = new Ioc(); } /// /// A unique Ioc container for shell-specific services. Wiped and recreated when the user switches shells. /// public static Ioc Ioc { get; private set; } = new Ioc(); /// /// Initializes the services for this shell's IoC. /// /// A that represents the asynchronous operation. public virtual Task InitServices(IServiceCollection serviceCollection) { Ioc.ConfigureServices(serviceCollection.BuildServiceProvider()); return Task.CompletedTask; } /// /// A ViewModel wrapper for all merged core data. /// public StrixDataRootViewModel DataRoot { get => (StrixDataRootViewModel)GetValue(DataRootProperty); set => SetValue(DataRootProperty, value); } /// /// The backing dependency property for . /// public static readonly DependencyProperty DataRootProperty = DependencyProperty.Register(nameof(DataRoot), typeof(StrixDataRootViewModel), typeof(Shell), new PropertyMetadata(null)); /// /// A ViewModel for notifications displayed to the user. /// public NotificationsViewModel Notifications { get => (NotificationsViewModel)GetValue(NotificationsProperty); set => SetValue(NotificationsProperty, value); } /// /// The backing dependency property for . /// public static readonly DependencyProperty NotificationsProperty = DependencyProperty.Register(nameof(Notifications), typeof(NotificationsViewModel), typeof(Shell), new PropertyMetadata(null)); private void ShellControl_Loaded(object sender, RoutedEventArgs e) { Loaded -= ShellControl_Loaded; SetupTitleBar(); } /// /// Sets properties of the title bar for this shell. /// protected virtual void SetupTitleBar() { #if NETFX_CORE CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = false; ApplicationViewTitleBar titleBar = ApplicationView.GetForCurrentView().TitleBar; titleBar.ButtonBackgroundColor = Resources["SystemAltHighColor"] as Color?; SystemNavigationManager currentView = SystemNavigationManager.GetForCurrentView(); currentView.AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed; #endif } } }