diff --git a/CoreAppUWP/Pages/MainPage.xaml b/CoreAppUWP/Pages/MainPage.xaml index 9d109f6..a821427 100644 --- a/CoreAppUWP/Pages/MainPage.xaml +++ b/CoreAppUWP/Pages/MainPage.xaml @@ -16,10 +16,10 @@ Height="48" VerticalAlignment="Top" Canvas.ZIndex="1" - IsHitTestVisible="True" - SizeChanged="CustomTitleBar_SizeChanged"> + IsHitTestVisible="True"> + @@ -32,7 +32,7 @@ @@ -60,7 +60,7 @@ diff --git a/CoreAppUWP/Pages/MainPage.xaml.cs b/CoreAppUWP/Pages/MainPage.xaml.cs index 8182c24..37e260d 100644 --- a/CoreAppUWP/Pages/MainPage.xaml.cs +++ b/CoreAppUWP/Pages/MainPage.xaml.cs @@ -1,5 +1,6 @@ using CoreAppUWP.Helpers; using CoreAppUWP.Pages.SettingsPages; +using Microsoft.UI.Windowing; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Media.Animation; @@ -38,6 +39,8 @@ public MainPage() protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); + if (AppWindowTitleBar.IsCustomizationSupported()) + { DragRegion.SizeChanged += CustomTitleBar_SizeChanged; } NavigationView_Navigate("Home", new EntranceNavigationTransitionInfo()); BackdropHelper.AddBackdropTypeChanged(Window.Current, OnBackdropTypeChanged); SystemNavigationManager.GetForCurrentView().BackRequested += System_BackRequested; @@ -47,6 +50,7 @@ protected override void OnNavigatedTo(NavigationEventArgs e) protected override void OnNavigatedFrom(NavigationEventArgs e) { base.OnNavigatedFrom(e); + DragRegion.SizeChanged -= CustomTitleBar_SizeChanged; BackdropHelper.RemoveBackdropTypeChanged(Window.Current, OnBackdropTypeChanged); SystemNavigationManager.GetForCurrentView().BackRequested -= System_BackRequested; CoreApplication.GetCurrentView().TitleBar.LayoutMetricsChanged -= TitleBar_LayoutMetricsChanged; @@ -141,10 +145,15 @@ private void On_Navigated(object sender, NavigationEventArgs e) private void NavigationViewControl_PaneClosing(NavigationView sender, NavigationViewPaneClosingEventArgs args) { - UpdateLeftPaddingColumn(); + UpdateTitlePaddingColumn(); } private void NavigationViewControl_PaneOpening(NavigationView sender, object args) + { + UpdateTitlePaddingColumn(); + } + + private void NavigationViewControl_DisplayModeChanged(NavigationView sender, NavigationViewDisplayModeChangedEventArgs args) { UpdateLeftPaddingColumn(); } @@ -161,12 +170,18 @@ private void UpdateLeftPaddingColumn() ? NavigationView.IsPaneToggleButtonVisible ? new GridLength(88) : new GridLength(44) - : NavigationView.IsPaneOpen ? new GridLength(44) : new GridLength(60); + : new GridLength(44); + UpdateTitlePaddingColumn(); } - private void NavigationViewControl_DisplayModeChanged(NavigationView sender, NavigationViewDisplayModeChangedEventArgs args) + private void UpdateTitlePaddingColumn() { - UpdateLeftPaddingColumn(); + TitlePaddingColumn.Width = + NavigationView.IsBackButtonVisible != NavigationViewBackButtonVisible.Collapsed + && NavigationView.DisplayMode != NavigationViewDisplayMode.Minimal + && !NavigationView.IsPaneOpen + ? new GridLength(16) + : new GridLength(0); } private void UpdateAppTitle(CoreApplicationViewTitleBar coreTitleBar) @@ -186,7 +201,7 @@ private void System_BackRequested(object sender, BackRequestedEventArgs e) private void CustomTitleBar_SizeChanged(object sender, SizeChangedEventArgs e) { RectInt32 Rect = new((ActualWidth - DragRegion.ActualWidth).GetActualPixel(), 0, DragRegion.ActualWidth.GetActualPixel(), DragRegion.ActualHeight.GetActualPixel()); - Window.Current.CoreWindow.GetAppWindow().TitleBar.SetDragRectangles([Rect]); + CoreWindow.GetForCurrentThread()?.GetAppWindow()?.TitleBar.SetDragRectangles([Rect]); } } } diff --git a/CoreAppUWP/Pages/SettingsPages/SettingsPage.xaml.cs b/CoreAppUWP/Pages/SettingsPages/SettingsPage.xaml.cs index 08f42b3..c43bebe 100644 --- a/CoreAppUWP/Pages/SettingsPages/SettingsPage.xaml.cs +++ b/CoreAppUWP/Pages/SettingsPages/SettingsPage.xaml.cs @@ -110,6 +110,7 @@ private async void Button_Click(object sender, RoutedEventArgs e) TitleBar.BackgroundColor = TitleBar.InactiveBackgroundColor = BackgroundColor; TitleBar.ButtonBackgroundColor = TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent; } + window.AssociateWithDispatcherQueue(DispatcherQueue); window.Title = Package.Current.DisplayName; window.SetIcon("favicon.ico"); window.Show(); diff --git a/README.md b/README.md index ad47b64..6307329 100644 --- a/README.md +++ b/README.md @@ -8,12 +8,12 @@ UWP running on .NET Core App ## Dictionary - [CoreAppUWP](#coreappuwp) - [Dictionary](#dictionary) - - [How to unlock Windows App SDK](#how-to-unlock-windows-app-sdk) + - [Unlock WAS](#unlock-was) - [Contributors](#contributors) - [Credits](#credits) -## How to unlock Windows App SDK -Import the registry file [EnableUWPWindow.reg](./EnableUWPWindow.reg) to unlock the Windows App SDK for UWP. +## Unlock WAS +Import the registry file [EnableUWPWindow.reg](./EnableUWPWindow.reg) to unlock the Windows App SDK for CoreWindow. ## Contributors [![Contributors](https://contrib.rocks/image?repo=wherewhere/CoreAppUWP)](https://github.com/wherewhere/CoreAppUWP/graphs/contributors "Contributors")