From 6571c79f775934ae03ce4e58fd7f82be8d35cd4b Mon Sep 17 00:00:00 2001 From: Tim Miller Date: Mon, 17 Jan 2022 15:35:40 -0500 Subject: [PATCH] More sidebar updates --- DrasticMaui.Sample/App.xaml.cs | 4 ++-- DrasticMaui.Sample/DrasticMauiSampleWindow.cs | 15 +++++---------- .../DrasticSideBarNavigationWindow.Windows.cs | 14 +++++++++++--- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/DrasticMaui.Sample/App.xaml.cs b/DrasticMaui.Sample/App.xaml.cs index cd87c50..93ffa59 100644 --- a/DrasticMaui.Sample/App.xaml.cs +++ b/DrasticMaui.Sample/App.xaml.cs @@ -24,9 +24,9 @@ public App(IServiceProvider provider) this.InitializeComponent(); var icon = MauiProgram.GetResourceFileContent("Icon.favicon.ico"); var menuList = new List(); + menuList.Add(new NavigationSidebarItem("Main Page", imageStream: icon, page: new NavigationPage(new MainPage(provider)))); menuList.Add(new NavigationSidebarItem("Test 1", imageStream: icon, page: new NavigationPage(new MauiTestPage()))); menuList.Add(new NavigationSidebarItem("Test 2", imageStream: icon, page: new MauiTestPage())); - menuList.Add(new NavigationSidebarItem("Test 3", imageStream: icon, page: new MainPage(provider))); this.sidebarMenuOptions = new SidebarMenuOptions("DrasticMaui", menuList, true); } @@ -47,5 +47,5 @@ private void TrayIcon_MenuClicked(object? sender, DrasticTrayMenuClickedEventArg /// protected override Window CreateWindow(IActivationState? activationState) - => new DrasticSideBarNavigationWindow(this.sidebarMenuOptions, this.Services); + => new DrasticMauiSampleWindow(this.sidebarMenuOptions, this.Services); } diff --git a/DrasticMaui.Sample/DrasticMauiSampleWindow.cs b/DrasticMaui.Sample/DrasticMauiSampleWindow.cs index 79688d4..77c07db 100644 --- a/DrasticMaui.Sample/DrasticMauiSampleWindow.cs +++ b/DrasticMaui.Sample/DrasticMauiSampleWindow.cs @@ -2,30 +2,25 @@ // Copyright (c) Drastic Actions. All rights reserved. // -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Threading.Tasks; using DrasticMaui.Models; using DrasticMaui.Overlays; using DrasticMaui.Tools; using Microsoft.Maui.Handlers; +using System.Reflection; namespace DrasticMaui.Sample { /// /// Drastic Maui Window. /// - public class DrasticMauiSampleWindow : DrasticMauiWindow + public class DrasticMauiSampleWindow : DrasticSideBarNavigationWindow { /// /// Initializes a new instance of the class. /// /// Service Provider. - public DrasticMauiSampleWindow(IServiceProvider services) - : base(services) + public DrasticMauiSampleWindow(SidebarMenuOptions options, IServiceProvider services) + : base(options, services) { this.DragAndDropOverlay = new DragAndDropOverlay(this); this.PageOverlay = new PageOverlay(this); @@ -56,7 +51,7 @@ protected override void OnCreated() public async Task TestTrayIcon() { #if __MACCATALYST__ - if (this.Handler is WindowHandler handler) + if (this.Handler is WindowHandler handler) { await handler.NativeView.SetFrameForUIWindow(new CoreGraphics.CGRect(0, 0, 100, 100)); } diff --git a/DrasticMaui/DrasticSideBarNavigationWindow.Windows.cs b/DrasticMaui/DrasticSideBarNavigationWindow.Windows.cs index 590aa79..526025d 100644 --- a/DrasticMaui/DrasticSideBarNavigationWindow.Windows.cs +++ b/DrasticMaui/DrasticSideBarNavigationWindow.Windows.cs @@ -13,6 +13,8 @@ public partial class DrasticSideBarNavigationWindow private Microsoft.UI.Xaml.FrameworkElement? page; private MauiNavigationView? navigationView; private NavigationRootView? navigationRootView; + private Page? selectedPage; + private IMauiContext? context; private Microsoft.Maui.Graphics.Rectangle backButton = new Microsoft.Maui.Graphics.Rectangle(0, 0, 100, 100); @@ -40,6 +42,8 @@ public async void SetupNavigationView() return; } + this.context = handler.MauiContext; + if (handler?.NativeView is not Microsoft.UI.Xaml.Window window) { return; @@ -83,7 +87,7 @@ private void NavigationRootView_Loaded(object sender, Microsoft.UI.Xaml.RoutedEv this.navigationView.IsBackEnabled = true; this.navigationView.SelectedItem = this.navigationView.MenuItems.FirstOrDefault(); this.navigationView.BackRequested += NavigationView_BackRequested; - this.navigationView.PaneDisplayMode = Microsoft.UI.Xaml.Controls.NavigationViewPaneDisplayMode.Auto; + this.navigationView.PaneDisplayMode = Microsoft.UI.Xaml.Controls.NavigationViewPaneDisplayMode.LeftCompact; this.navigationView.IsPaneToggleButtonVisible = true; this.isInitialized = true; @@ -91,9 +95,9 @@ private void NavigationRootView_Loaded(object sender, Microsoft.UI.Xaml.RoutedEv private void NavigationView_BackRequested(Microsoft.UI.Xaml.Controls.NavigationView sender, Microsoft.UI.Xaml.Controls.NavigationViewBackRequestedEventArgs args) { - if (sender.Content is Microsoft.UI.Xaml.Controls.Frame frame) + if (this.selectedPage is not null && this.context is not null) { - frame.GoBack(); + this.selectedPage.SendBackButtonPressed(); } } @@ -126,6 +130,10 @@ private void NavigationView_SelectionChanged(Microsoft.UI.Xaml.Controls.Navigati return; } + this.selectedPage = selectedItem.Page; + + this.selectedPage.Parent = this; + if (this.Handler.MauiContext is null) { return;