Skip to content
This repository has been archived by the owner on Dec 19, 2022. It is now read-only.

Commit

Permalink
More sidebar updates
Browse files Browse the repository at this point in the history
  • Loading branch information
drasticactions committed Jan 17, 2022
1 parent cc88edb commit 6571c79
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
4 changes: 2 additions & 2 deletions DrasticMaui.Sample/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public App(IServiceProvider provider)
this.InitializeComponent();
var icon = MauiProgram.GetResourceFileContent("Icon.favicon.ico");
var menuList = new List<NavigationSidebarItem>();
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);
}

Expand All @@ -47,5 +47,5 @@ private void TrayIcon_MenuClicked(object? sender, DrasticTrayMenuClickedEventArg

/// <inheritdoc/>
protected override Window CreateWindow(IActivationState? activationState)
=> new DrasticSideBarNavigationWindow(this.sidebarMenuOptions, this.Services);
=> new DrasticMauiSampleWindow(this.sidebarMenuOptions, this.Services);
}
15 changes: 5 additions & 10 deletions DrasticMaui.Sample/DrasticMauiSampleWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,25 @@
// Copyright (c) Drastic Actions. All rights reserved.
// </copyright>

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
{
/// <summary>
/// Drastic Maui Window.
/// </summary>
public class DrasticMauiSampleWindow : DrasticMauiWindow
public class DrasticMauiSampleWindow : DrasticSideBarNavigationWindow
{
/// <summary>
/// Initializes a new instance of the <see cref="DrasticMauiSampleWindow"/> class.
/// </summary>
/// <param name="services">Service Provider.</param>
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);
Expand Down Expand Up @@ -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));
}
Expand Down
14 changes: 11 additions & 3 deletions DrasticMaui/DrasticSideBarNavigationWindow.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -40,6 +42,8 @@ public async void SetupNavigationView()
return;
}

this.context = handler.MauiContext;

if (handler?.NativeView is not Microsoft.UI.Xaml.Window window)
{
return;
Expand Down Expand Up @@ -83,17 +87,17 @@ 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;
}

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();
}
}

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6571c79

Please sign in to comment.