From 549d30892d89e472b4b6d4059c8abd04f8c364c0 Mon Sep 17 00:00:00 2001 From: Niels Laute Date: Tue, 2 Sep 2025 07:02:43 +0200 Subject: [PATCH] [Hosts File Editor] Using TitleBar (#41416) Using `TitleBar` instead of our custom XAML. No visual changes: image - [X] Closes: #41414 - [ ] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [ ] **Tests:** Added/updated and all pass - [ ] **Localization:** All end-user-facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx ## Detailed Description of the Pull Request / Additional comments ## Validation Steps Performed --- .../Hosts/Hosts/HostsXAML/MainWindow.xaml | 31 ++++++------------- .../Hosts/Hosts/HostsXAML/MainWindow.xaml.cs | 21 ++----------- 2 files changed, 11 insertions(+), 41 deletions(-) diff --git a/src/modules/Hosts/Hosts/HostsXAML/MainWindow.xaml b/src/modules/Hosts/Hosts/HostsXAML/MainWindow.xaml index 73a883f68b..92d1594556 100644 --- a/src/modules/Hosts/Hosts/HostsXAML/MainWindow.xaml +++ b/src/modules/Hosts/Hosts/HostsXAML/MainWindow.xaml @@ -20,27 +20,14 @@ - - - - - - - - - - + + + + + + diff --git a/src/modules/Hosts/Hosts/HostsXAML/MainWindow.xaml.cs b/src/modules/Hosts/Hosts/HostsXAML/MainWindow.xaml.cs index 85df8e7313..d1937d508d 100644 --- a/src/modules/Hosts/Hosts/HostsXAML/MainWindow.xaml.cs +++ b/src/modules/Hosts/Hosts/HostsXAML/MainWindow.xaml.cs @@ -9,19 +9,15 @@ using HostsUILib.Helpers; using HostsUILib.Views; using ManagedCommon; using Microsoft.PowerToys.Telemetry; +using Microsoft.UI.Windowing; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Media; using Microsoft.Windows.ApplicationModel.Resources; using WinUIEx; -// To learn more about WinUI, the WinUI project structure, -// and more about our project templates, see: http://aka.ms/winui-project-info. namespace Hosts { - /// - /// An empty window that can be used on its own or navigated to within a Frame. - /// public sealed partial class MainWindow : WindowEx { private HostsMainPage MainPage { get; } @@ -38,31 +34,18 @@ namespace Hosts var title = Host.GetService().IsElevated ? loader.GetString("WindowAdminTitle") : loader.GetString("WindowTitle"); Title = title; - AppTitleTextBlock.Text = title; + titleBar.Title = title; var handle = this.GetWindowHandle(); WindowHelpers.ForceTopBorder1PixelInsetOnWindows10(handle); WindowHelpers.BringToForeground(handle); - Activated += MainWindow_Activated; MainPage = Host.GetService(); PowerToysTelemetry.Log.WriteEvent(new HostEditorStartFinishEvent() { TimeStamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }); } - private void MainWindow_Activated(object sender, WindowActivatedEventArgs args) - { - if (args.WindowActivationState == WindowActivationState.Deactivated) - { - AppTitleTextBlock.Foreground = (SolidColorBrush)App.Current.Resources["WindowCaptionForegroundDisabled"]; - } - else - { - AppTitleTextBlock.Foreground = (SolidColorBrush)App.Current.Resources["WindowCaptionForeground"]; - } - } - private void Grid_Loaded(object sender, RoutedEventArgs e) { MainGrid.Children.Add(MainPage);