From e7fe6f9b15b121479077ec16ce0e476e37fb2cc3 Mon Sep 17 00:00:00 2001 From: Ramez Ragaa Date: Wed, 10 Apr 2024 16:21:47 +0200 Subject: [PATCH] feat: add support for ExtendIntoTitleBar on WPF --- .../UI/Controls/UnoWpfWindow.cs | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/Uno.UI.Runtime.Skia.Wpf/UI/Controls/UnoWpfWindow.cs b/src/Uno.UI.Runtime.Skia.Wpf/UI/Controls/UnoWpfWindow.cs index 778b458077a5..29eb6636ea3d 100644 --- a/src/Uno.UI.Runtime.Skia.Wpf/UI/Controls/UnoWpfWindow.cs +++ b/src/Uno.UI.Runtime.Skia.Wpf/UI/Controls/UnoWpfWindow.cs @@ -4,6 +4,9 @@ using System.Collections.Concurrent; using System.ComponentModel; using System.IO; +using System.Windows; +using System.Windows.Shell; +using Windows.ApplicationModel.Core; using Uno.Foundation.Logging; using Uno.UI.Xaml.Core; using Windows.UI.ViewManagement; @@ -41,11 +44,14 @@ public UnoWpfWindow(WinUI.Window winUIWindow, WinUI.XamlRoot xamlRoot) _applicationView = ApplicationView.GetForWindowId(winUIWindow.AppWindow.Id); _applicationView.PropertyChanged += OnApplicationViewPropertyChanged; + CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBarChanged += UpdateWindowPropertiesFromCoreApplication; + Closed += UnoWpfWindow_Closed; Activated += UnoWpfWindow_Activated; UpdateWindowPropertiesFromPackage(); UpdateWindowPropertiesFromApplicationView(); + UpdateWindowPropertiesFromCoreApplication(); } private void UnoWpfWindow_Activated(object? sender, EventArgs e) @@ -63,6 +69,7 @@ private void UnoWpfWindow_Activated(object? sender, EventArgs e) private void UnoWpfWindow_Closed(object? sender, EventArgs e) { _applicationView.PropertyChanged -= OnApplicationViewPropertyChanged; + CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBarChanged -= UpdateWindowPropertiesFromCoreApplication; } internal UnoWpfWindowHost Host { get; private set; } @@ -114,4 +121,28 @@ internal void UpdateWindowPropertiesFromPackage() Title = Windows.ApplicationModel.Package.Current.DisplayName; } } + + internal void UpdateWindowPropertiesFromCoreApplication() + { + var coreApplicationView = CoreApplication.GetCurrentView(); + if (coreApplicationView.TitleBar.ExtendViewIntoTitleBar) + { + WindowStyle = System.Windows.WindowStyle.None; + WindowChrome.SetWindowChrome(this, new WindowChrome + { + UseAeroCaptionButtons = false, + // this removes the thin white bar at the top, but this causes the window to grow a little. + // No work around has been found for this yet. + CaptionHeight = 0 + }); + + // for some reason touchpad physical presses work without this, but not "taps" + WindowChrome.SetIsHitTestVisibleInChrome((IInputElement)Content, true); + } + else + { + WindowStyle = System.Windows.WindowStyle.SingleBorderWindow; + ClearValue(WindowChrome.WindowChromeProperty); + } + } }