Skip to content

Commit

Permalink
feat: add support for ExtendIntoTitleBar on WPF
Browse files Browse the repository at this point in the history
  • Loading branch information
ramezgerges committed Apr 12, 2024
1 parent cb50e60 commit e7fe6f9
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/Uno.UI.Runtime.Skia.Wpf/UI/Controls/UnoWpfWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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; }
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit e7fe6f9

Please sign in to comment.