Skip to content

Commit

Permalink
修改标题栏缩进逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
wherewhere committed Nov 5, 2023
1 parent 791322b commit d60c7c2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
8 changes: 4 additions & 4 deletions CoreAppUWP/Pages/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
Height="48"
VerticalAlignment="Top"
Canvas.ZIndex="1"
IsHitTestVisible="True"
SizeChanged="CustomTitleBar_SizeChanged">
IsHitTestVisible="True">
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="LeftPaddingColumn" Width="0" />
<ColumnDefinition x:Name="TitlePaddingColumn" Width="0" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
Expand All @@ -32,7 +32,7 @@
</Grid.ChildrenTransitions>
<Grid
x:Name="AppTitle"
Grid.Column="1"
Grid.Column="2"
Margin="8,0"
ColumnSpacing="20">
<Grid.ColumnDefinitions>
Expand Down Expand Up @@ -60,7 +60,7 @@
<Border
x:Name="DragRegion"
Grid.Column="1"
Grid.ColumnSpan="4"
Grid.ColumnSpan="5"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="{ThemeResource SystemControlTransparentBrush}" />
Expand Down
25 changes: 20 additions & 5 deletions CoreAppUWP/Pages/MainPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
}
Expand All @@ -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)
Expand All @@ -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]);
}
}
}
1 change: 1 addition & 0 deletions CoreAppUWP/Pages/SettingsPages/SettingsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit d60c7c2

Please sign in to comment.