From 2ddf59c2ed2d3ae9df4319bf6094d4ce610742e2 Mon Sep 17 00:00:00 2001 From: wherewhere Date: Mon, 6 Nov 2023 21:36:29 +0800 Subject: [PATCH] =?UTF-8?q?=E7=8E=B0=E5=9C=A8=20Win32=20=E7=AA=97=E5=8F=A3?= =?UTF-8?q?=E6=9C=80=E5=B0=8F=E5=8C=96=E4=B8=8D=E4=BC=9A=E5=87=BA=E9=94=99?= =?UTF-8?q?=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CoreAppUWP/App.xaml | 5 ----- CoreAppUWP/Controls/DesktopWindow.cs | 5 ++--- CoreAppUWP/Pages/MainPage.xaml.cs | 2 +- .../Pages/SettingsPages/SettingsPage.xaml | 14 +++++++++++- .../Pages/SettingsPages/SettingsPage.xaml.cs | 22 +++++-------------- .../SettingsPages/SettingsViewModel.cs | 8 +++++-- 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/CoreAppUWP/App.xaml b/CoreAppUWP/App.xaml index 5cfd9d7..e87f219 100644 --- a/CoreAppUWP/App.xaml +++ b/CoreAppUWP/App.xaml @@ -14,11 +14,6 @@ 641 - 0 - -4,0,12,0 - - 67 - 0,48,0,0 1,1,0,0 diff --git a/CoreAppUWP/Controls/DesktopWindow.cs b/CoreAppUWP/Controls/DesktopWindow.cs index 04b86f4..03ac5a9 100644 --- a/CoreAppUWP/Controls/DesktopWindow.cs +++ b/CoreAppUWP/Controls/DesktopWindow.cs @@ -105,6 +105,7 @@ public static Task CreateAsync(Action la DesktopWindowXamlSource source = new(); source.Initialize(window.Id); DesktopChildSiteBridge bridge = source.SiteBridge; + bridge.ResizePolicy = ContentSizePolicy.ResizeContentToParentWindow; window.Changed += (sender, args) => { if (args.DidPresenterChange) @@ -114,7 +115,6 @@ public static Task CreateAsync(Action la } }; bridge.Show(); - bridge.ResizePolicy = ContentSizePolicy.ResizeContentToParentWindow; launched(source); hook.EndHook(); DesktopWindow desktopWindow = new() @@ -153,11 +153,11 @@ public static Task CreateAsync(DispatcherQueue dispatcherQueue, A HookWindowingModel hook = new(); hook.StartHook(); AppWindow window = AppWindow.Create(); - window.Destroying += (sender, args) => dispatcherQueue.EnqueueEventLoopExit(); window.AssociateWithDispatcherQueue(dispatcherQueue); DesktopWindowXamlSource source = new(); source.Initialize(window.Id); DesktopChildSiteBridge bridge = source.SiteBridge; + bridge.ResizePolicy = ContentSizePolicy.ResizeContentToParentWindow; window.Changed += (sender, args) => { if (args.DidPresenterChange) @@ -167,7 +167,6 @@ public static Task CreateAsync(DispatcherQueue dispatcherQueue, A } }; bridge.Show(); - bridge.ResizePolicy = ContentSizePolicy.ResizeContentToParentWindow; launched(source); hook.EndHook(); DesktopWindow desktopWindow = new() diff --git a/CoreAppUWP/Pages/MainPage.xaml.cs b/CoreAppUWP/Pages/MainPage.xaml.cs index 64f43b8..6e88c64 100644 --- a/CoreAppUWP/Pages/MainPage.xaml.cs +++ b/CoreAppUWP/Pages/MainPage.xaml.cs @@ -232,7 +232,7 @@ private void UpdateAppTitle(CoreApplicationViewTitleBar coreTitleBar) private void UpdateAppTitle(AppWindow appWindow) { IntPtr hwnd = (IntPtr)appWindow.Id.Value; - RightPaddingColumn.Width = new GridLength(appWindow.TitleBar.RightInset.GetDisplayPixel(hwnd)); + RightPaddingColumn.Width = new GridLength(Math.Max(0, appWindow.TitleBar.RightInset.GetDisplayPixel(hwnd))); } private void System_BackRequested(object sender, BackRequestedEventArgs e) diff --git a/CoreAppUWP/Pages/SettingsPages/SettingsPage.xaml b/CoreAppUWP/Pages/SettingsPages/SettingsPage.xaml index e0636f0..2eee43e 100644 --- a/CoreAppUWP/Pages/SettingsPages/SettingsPage.xaml +++ b/CoreAppUWP/Pages/SettingsPages/SettingsPage.xaml @@ -5,6 +5,7 @@ xmlns:animatedvisuals="using:Microsoft.UI.Xaml.Controls.AnimatedVisuals" xmlns:common="using:CoreAppUWP.Common" xmlns:controls="using:CoreAppUWP.Controls" + xmlns:converters="using:CommunityToolkit.WinUI.UI.Converters" xmlns:cwuc="using:CommunityToolkit.WinUI.UI.Controls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:interopservices="using:System.Runtime.InteropServices" @@ -14,6 +15,9 @@ DataContext="{x:Bind Provider, Mode=OneWay}" NavigationCacheMode="Enabled" mc:Ignorable="d"> + + + - + Mica MicaAlt Acrylic @@ -352,11 +356,19 @@ + diff --git a/CoreAppUWP/Pages/SettingsPages/SettingsPage.xaml.cs b/CoreAppUWP/Pages/SettingsPages/SettingsPage.xaml.cs index 8e7cf38..f0d29c1 100644 --- a/CoreAppUWP/Pages/SettingsPages/SettingsPage.xaml.cs +++ b/CoreAppUWP/Pages/SettingsPages/SettingsPage.xaml.cs @@ -70,9 +70,7 @@ private async void Button_Click(object sender, RoutedEventArgs e) SettingsHelper.LocalObject.Clear(); SettingsHelper.SetDefaultSettings(); if (Reset.Flyout is Flyout flyout_reset) - { - flyout_reset.Hide(); - } + { flyout_reset.Hide(); } _ = Refresh(true); break; case "ExitPIP": @@ -82,9 +80,7 @@ private async void Button_Click(object sender, RoutedEventArgs e) _ = ApplicationView.GetForCurrentView().TryEnterViewModeAsync(ApplicationViewMode.Default); } else if (this.GetWindowForElement() is DesktopWindow desktopWindow) - { - desktopWindow.AppWindow.SetPresenter(AppWindowPresenterKind.Default); - } + { desktopWindow.AppWindow.SetPresenter(AppWindowPresenterKind.Default); } break; case "EnterPIP": if (IsCoreWindow) @@ -93,17 +89,13 @@ private async void Button_Click(object sender, RoutedEventArgs e) _ = ApplicationView.GetForCurrentView().TryEnterViewModeAsync(ApplicationViewMode.CompactOverlay); } else if (this.GetWindowForElement() is DesktopWindow desktopWindow) - { - desktopWindow.AppWindow.SetPresenter(AppWindowPresenterKind.CompactOverlay); - } + { desktopWindow.AppWindow.SetPresenter(AppWindowPresenterKind.CompactOverlay); } break; - case "NewWindow": + case "NewWindow" when IsCoreWindow: _ = await WindowHelper.CreateWindowAsync(window => { if (SettingsHelper.Get(SettingsHelper.IsExtendsTitleBar)) - { - CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true; - } + { CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true; } Frame _frame = new(); window.Content = _frame; ThemeHelper.Initialize(window); @@ -120,9 +112,7 @@ private async void Button_Click(object sender, RoutedEventArgs e) }).ConfigureAwait(false); if (AppWindowTitleBar.IsCustomizationSupported() && SettingsHelper.Get(SettingsHelper.IsExtendsTitleBar)) - { - window.ExtendsContentIntoTitleBar = true; - } + { window.ExtendsContentIntoTitleBar = true; } ThemeHelper.Initialize(window); BackdropHelper.SetBackdrop(window, SettingsHelper.Get(SettingsHelper.SelectedBackdrop)); AppWindow appWindow = window.AppWindow; diff --git a/CoreAppUWP/ViewModels/SettingsPages/SettingsViewModel.cs b/CoreAppUWP/ViewModels/SettingsPages/SettingsViewModel.cs index 33c8858..52eb571 100644 --- a/CoreAppUWP/ViewModels/SettingsPages/SettingsViewModel.cs +++ b/CoreAppUWP/ViewModels/SettingsPages/SettingsViewModel.cs @@ -48,7 +48,7 @@ public int SelectedTheme } } - public static int SelectedBackdrop + public int SelectedBackdrop { get => (int)SettingsHelper.Get(SettingsHelper.SelectedBackdrop); set @@ -58,6 +58,7 @@ public static int SelectedBackdrop BackdropType type = (BackdropType)value; SettingsHelper.Set(SettingsHelper.SelectedBackdrop, type); BackdropHelper.SetAllBackdrop(type); + RaisePropertyChangedEvent(); } } } @@ -160,7 +161,10 @@ public async Task Refresh(bool reset) { if (reset) { - RaisePropertyChangedEvent(nameof(SelectedTheme)); + RaisePropertyChangedEvent( + nameof(SelectedTheme), + nameof(SelectedBackdrop), + nameof(IsExtendsTitleBar)); } await GetAboutTextBlockTextAsync(); }