From 25c6b3f135efc62566d7268671053954ba52a7b5 Mon Sep 17 00:00:00 2001 From: Niels Laute Date: Fri, 7 Mar 2025 15:07:53 +0100 Subject: [PATCH 01/18] Move helpers out of App.xaml.cs --- WinUIGallery/App.xaml.cs | 54 ++----------------- WinUIGallery/Helpers/EnumHelper.cs | 22 ++++++++ WinUIGallery/Helpers/ThemeHelper.cs | 4 +- WinUIGallery/Helpers/VersionHelper.cs | 35 ++++++++++++ WinUIGallery/Pages/HomePage.xaml.cs | 2 +- WinUIGallery/Pages/SettingsPage.xaml.cs | 4 +- .../Samples/ControlPages/TitleBarPage.xaml.cs | 2 +- 7 files changed, 66 insertions(+), 57 deletions(-) create mode 100644 WinUIGallery/Helpers/EnumHelper.cs create mode 100644 WinUIGallery/Helpers/VersionHelper.cs diff --git a/WinUIGallery/App.xaml.cs b/WinUIGallery/App.xaml.cs index a39a23bd9..2bf88d799 100644 --- a/WinUIGallery/App.xaml.cs +++ b/WinUIGallery/App.xaml.cs @@ -10,20 +10,16 @@ using System; using System.Diagnostics; using System.Linq; -using System.Reflection; -using WinUIGallery.Models; -using WinUIGallery.Helpers; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Navigation; using Microsoft.Windows.AppLifecycle; -using Windows.ApplicationModel.Activation; -using WASDK = Microsoft.WindowsAppSDK; using Microsoft.Windows.AppNotifications; using Microsoft.Windows.AppNotifications.Builder; -using System.Collections.Generic; -using static WinUIGallery.Helpers.Win32; +using Windows.ApplicationModel.Activation; +using WinUIGallery.Helpers; using WinUIGallery.Pages; +using static WinUIGallery.Helpers.Win32; namespace WinUIGallery; @@ -37,34 +33,6 @@ sealed partial class App : Application private static int registeredKeyPressedHook = 0; private HookProc keyEventHook; - - public static string WinAppSdkDetails - { - // TODO: restore patch number and version tag when WinAppSDK supports them both - get => string.Format("Windows App SDK {0}.{1}", - WASDK.Release.Major, WASDK.Release.Minor); - } - - public static string WinAppSdkRuntimeDetails - { - get - { - try - { - // Retrieve Windows App Runtime version info dynamically - IEnumerable windowsAppRuntimeVersion = - from module in Process.GetCurrentProcess().Modules.OfType() - where module.FileName.EndsWith("Microsoft.WindowsAppRuntime.Insights.Resource.dll") - select FileVersionInfo.GetVersionInfo(module.FileName); - return WinAppSdkDetails + ", Windows App Runtime " + windowsAppRuntimeVersion.First().FileVersion; - } - catch - { - return WinAppSdkDetails + $", Windows App Runtime {WASDK.Runtime.Version.Major}.{WASDK.Runtime.Version.Minor}"; - } - } - } - /// /// Get the initial window created for this app. /// @@ -83,22 +51,6 @@ public App() UnhandledException += HandleExceptions; } - /// - /// Converts a string into a enum. - /// - /// The output enum type. - /// The input text. - /// The parsed enum. - /// Thrown when the TEnum type is not a enum. - public static TEnum GetEnum(string text) where TEnum : struct - { - if (!typeof(TEnum).GetTypeInfo().IsEnum) - { - throw new InvalidOperationException("Generic parameter 'TEnum' must be an enum."); - } - return (TEnum)Enum.Parse(typeof(TEnum), text); - } - /// /// Invoked when the application is launched normally by the end user. Other entry points /// will be used such as when the application is launched to open a specific file. diff --git a/WinUIGallery/Helpers/EnumHelper.cs b/WinUIGallery/Helpers/EnumHelper.cs new file mode 100644 index 000000000..d12d8b4cb --- /dev/null +++ b/WinUIGallery/Helpers/EnumHelper.cs @@ -0,0 +1,22 @@ +using System; +using System.Reflection; + +namespace WinUIGallery.Helpers; +internal static class EnumHelper +{ + /// + /// Converts a string into a enum. + /// + /// The output enum type. + /// The input text. + /// The parsed enum. + /// Thrown when the TEnum type is not a enum. + public static TEnum GetEnum(string text) where TEnum : struct + { + if (!typeof(TEnum).GetTypeInfo().IsEnum) + { + throw new InvalidOperationException("Generic parameter 'TEnum' must be an enum."); + } + return (TEnum)Enum.Parse(typeof(TEnum), text); + } +} diff --git a/WinUIGallery/Helpers/ThemeHelper.cs b/WinUIGallery/Helpers/ThemeHelper.cs index a80d91265..d160ce80b 100644 --- a/WinUIGallery/Helpers/ThemeHelper.cs +++ b/WinUIGallery/Helpers/ThemeHelper.cs @@ -29,7 +29,7 @@ public static ElementTheme ActualTheme } } - return WinUIGallery.App.GetEnum(App.Current.RequestedTheme.ToString()); + return EnumHelper.GetEnum(App.Current.RequestedTheme.ToString()); } } @@ -75,7 +75,7 @@ public static void Initialize() if (savedTheme != null) { - RootTheme = WinUIGallery.App.GetEnum(savedTheme); + RootTheme = EnumHelper.GetEnum(savedTheme); } } } diff --git a/WinUIGallery/Helpers/VersionHelper.cs b/WinUIGallery/Helpers/VersionHelper.cs new file mode 100644 index 000000000..23e7bc3cc --- /dev/null +++ b/WinUIGallery/Helpers/VersionHelper.cs @@ -0,0 +1,35 @@ +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using WASDK = Microsoft.WindowsAppSDK; + +namespace WinUIGallery.Helpers; +internal static class VersionHelper +{ + public static string WinAppSdkDetails + { + // TODO: restore patch number and version tag when WinAppSDK supports them both + get => string.Format("Windows App SDK {0}.{1}", + WASDK.Release.Major, WASDK.Release.Minor); + } + + public static string WinAppSdkRuntimeDetails + { + get + { + try + { + // Retrieve Windows App Runtime version info dynamically + IEnumerable windowsAppRuntimeVersion = + from module in Process.GetCurrentProcess().Modules.OfType() + where module.FileName.EndsWith("Microsoft.WindowsAppRuntime.Insights.Resource.dll") + select FileVersionInfo.GetVersionInfo(module.FileName); + return WinAppSdkDetails + ", Windows App Runtime " + windowsAppRuntimeVersion.First().FileVersion; + } + catch + { + return WinAppSdkDetails + $", Windows App Runtime {WASDK.Runtime.Version.Major}.{WASDK.Runtime.Version.Minor}"; + } + } + } +} diff --git a/WinUIGallery/Pages/HomePage.xaml.cs b/WinUIGallery/Pages/HomePage.xaml.cs index dab0088c0..1cfb66d83 100644 --- a/WinUIGallery/Pages/HomePage.xaml.cs +++ b/WinUIGallery/Pages/HomePage.xaml.cs @@ -22,7 +22,7 @@ public HomePage() this.InitializeComponent(); } - public string WinAppSdkDetails => App.WinAppSdkDetails; + public string WinAppSdkDetails => VersionHelper.WinAppSdkDetails; protected override void OnNavigatedTo(NavigationEventArgs e) { diff --git a/WinUIGallery/Pages/SettingsPage.xaml.cs b/WinUIGallery/Pages/SettingsPage.xaml.cs index 30c451f73..f360140c3 100644 --- a/WinUIGallery/Pages/SettingsPage.xaml.cs +++ b/WinUIGallery/Pages/SettingsPage.xaml.cs @@ -32,7 +32,7 @@ public string Version } } - public string WinAppSdkRuntimeDetails => App.WinAppSdkRuntimeDetails; + public string WinAppSdkRuntimeDetails => VersionHelper.WinAppSdkRuntimeDetails; private int lastNavigationSelectionMode = 0; public SettingsPage() @@ -89,7 +89,7 @@ private void themeMode_SelectionChanged(object sender, RoutedEventArgs e) string color; if (selectedTheme != null) { - ThemeHelper.RootTheme = App.GetEnum(selectedTheme); + ThemeHelper.RootTheme = EnumHelper.GetEnum(selectedTheme); if (selectedTheme == "Dark") { TitleBarHelper.SetCaptionButtonColors(window, Colors.White); diff --git a/WinUIGallery/Samples/ControlPages/TitleBarPage.xaml.cs b/WinUIGallery/Samples/ControlPages/TitleBarPage.xaml.cs index 7ad079bbb..faf0ef842 100644 --- a/WinUIGallery/Samples/ControlPages/TitleBarPage.xaml.cs +++ b/WinUIGallery/Samples/ControlPages/TitleBarPage.xaml.cs @@ -206,7 +206,7 @@ private void TitleBarHeightComboBox_SelectionChanged(object sender, SelectionCha if (selectedHeight != null && window != null && window.ExtendsContentIntoTitleBar) { - window.AppWindow.TitleBar.PreferredHeightOption = App.GetEnum(selectedHeight); + window.AppWindow.TitleBar.PreferredHeightOption = EnumHelper.GetEnum(selectedHeight); } } From 08b7d45e50072d323cf22b65a7dca7e3d0dc8546 Mon Sep 17 00:00:00 2001 From: Niels Laute Date: Fri, 7 Mar 2025 15:12:48 +0100 Subject: [PATCH 02/18] Update NugetPackages --- WinUIGallery/WinUIGallery.csproj | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/WinUIGallery/WinUIGallery.csproj b/WinUIGallery/WinUIGallery.csproj index 13a560571..9800b8444 100644 --- a/WinUIGallery/WinUIGallery.csproj +++ b/WinUIGallery/WinUIGallery.csproj @@ -119,16 +119,16 @@ - + - - - - - - + + + + + + - + From b4e2d9ed0e390a6045508f9442994336a2a0dd80 Mon Sep 17 00:00:00 2001 From: Niels Laute Date: Sat, 8 Mar 2025 12:18:13 +0100 Subject: [PATCH 03/18] Adding MainWindow and new TitleBar --- WinUIGallery/App.xaml.cs | 68 +----- .../Helpers/NavigationOrientationHelper.cs | 11 +- .../ProtocolActivationClipboardHelper.cs | 17 +- WinUIGallery/Helpers/TitleBarHelper.cs | 6 +- ...avigationRootPage.xaml => MainWindow.xaml} | 171 ++++++---------- ...ionRootPage.xaml.cs => MainWindow.xaml.cs} | 193 ++++++------------ WinUIGallery/Pages/AllControlsPage.xaml.cs | 8 +- WinUIGallery/Pages/HomePage.xaml.cs | 5 +- WinUIGallery/Pages/ItemPage.xaml.cs | 83 ++++---- WinUIGallery/Pages/ItemsPageBase.cs | 2 +- WinUIGallery/Pages/SearchResultsPage.xaml.cs | 8 +- WinUIGallery/Pages/SectionPage.xaml.cs | 18 +- WinUIGallery/Pages/SettingsPage.xaml.cs | 25 +-- .../CreateMultipleWindowsPage.xaml.cs | 7 +- .../Fundamentals/XamlResourcesPage.xaml.cs | 2 +- .../ControlPages/HyperlinkButtonPage.xaml.cs | 2 +- WinUIGallery/WinUIGallery.csproj | 9 +- 17 files changed, 240 insertions(+), 395 deletions(-) rename WinUIGallery/{Pages/NavigationRootPage.xaml => MainWindow.xaml} (75%) rename WinUIGallery/{Pages/NavigationRootPage.xaml.cs => MainWindow.xaml.cs} (81%) diff --git a/WinUIGallery/App.xaml.cs b/WinUIGallery/App.xaml.cs index 2bf88d799..ed21f6caa 100644 --- a/WinUIGallery/App.xaml.cs +++ b/WinUIGallery/App.xaml.cs @@ -28,19 +28,12 @@ namespace WinUIGallery; /// sealed partial class App : Application { - private static Window startupWindow; + internal static MainWindow MainWindow { get; private set; } = null!; + private static Win32WindowHelper win32WindowHelper; private static int registeredKeyPressedHook = 0; private HookProc keyEventHook; - /// - /// Get the initial window created for this app. - /// - public static Window StartupWindow - { - get => startupWindow; - } - /// /// Initializes the singleton Application object. This is the first line of authored code /// executed, and as such is the logical equivalent of main() or WinMain(). @@ -60,10 +53,10 @@ protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs ar { IdleSynchronizer.Init(); - startupWindow = WindowHelper.CreateWindow(); - startupWindow.ExtendsContentIntoTitleBar = true; + MainWindow = new MainWindow(); + WindowHelper.TrackWindow(MainWindow); - win32WindowHelper = new Win32WindowHelper(startupWindow); + win32WindowHelper = new Win32WindowHelper(MainWindow); win32WindowHelper.SetWindowMinMaxSize(new Win32WindowHelper.POINT() { x = 500, y = 500 }); #if DEBUG @@ -105,9 +98,7 @@ private async void EnsureWindow() { await ControlInfoDataSource.Instance.GetGroupsAsync(); await IconsDataSource.Instance.LoadIcons(); - - Frame rootFrame = GetRootFrame(); - + MainWindow.AddNavigationMenuItems(); ThemeHelper.Initialize(); var targetPageType = typeof(HomePage); @@ -138,57 +129,16 @@ private async void EnsureWindow() } } - var rootPage = StartupWindow.Content as NavigationRootPage; - rootPage.Navigate(targetPageType, targetPageArguments); + MainWindow.Navigate(targetPageType, targetPageArguments); if (targetPageType == typeof(HomePage)) { - var navItem = (NavigationViewItem)rootPage.NavigationView.MenuItems[0]; + var navItem = (NavigationViewItem)MainWindow.NavigationView.MenuItems[0]; navItem.IsSelected = true; } // Activate the startup window. - StartupWindow.Activate(); - } - - /// - /// Gets the frame of the StartupWindow. - /// - /// The frame of the StartupWindow. - /// Thrown if the window doesn't have a frame with the name "rootFrame". - public Frame GetRootFrame() - { - Frame rootFrame; - if (StartupWindow.Content is NavigationRootPage rootPage) - { - rootFrame = (Frame)rootPage.FindName("rootFrame"); - } - else - { - rootPage = new NavigationRootPage(); - rootFrame = (Frame)rootPage.FindName("rootFrame"); - if (rootFrame == null) - { - throw new Exception("Root frame not found"); - } - SuspensionManager.RegisterFrame(rootFrame, "AppFrame"); - rootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0]; - rootFrame.NavigationFailed += OnNavigationFailed; - - StartupWindow.Content = rootPage; - } - - return rootFrame; - } - - /// - /// Invoked when Navigation to a certain page fails - /// - /// The Frame which failed navigation - /// Details about the navigation failure - void OnNavigationFailed(object sender, NavigationFailedEventArgs e) - { - throw new Exception("Failed to load Page " + e.SourcePageType.FullName); + MainWindow.Activate(); } /// diff --git a/WinUIGallery/Helpers/NavigationOrientationHelper.cs b/WinUIGallery/Helpers/NavigationOrientationHelper.cs index e2f834a02..b7760cbcf 100644 --- a/WinUIGallery/Helpers/NavigationOrientationHelper.cs +++ b/WinUIGallery/Helpers/NavigationOrientationHelper.cs @@ -29,9 +29,9 @@ public static bool IsLeftMode() } } - public static void IsLeftModeForElement(bool isLeftMode, UIElement element) + public static void IsLeftModeForElement(bool isLeftMode) { - UpdateNavigationViewForElement(isLeftMode, element); + UpdateNavigationViewForElement(isLeftMode); if (NativeHelper.IsAppPackaged) { ApplicationData.Current.LocalSettings.Values[IsLeftModeKey] = isLeftMode; @@ -42,19 +42,16 @@ public static void IsLeftModeForElement(bool isLeftMode, UIElement element) } } - public static void UpdateNavigationViewForElement(bool isLeftMode, UIElement element) + public static void UpdateNavigationViewForElement(bool isLeftMode) { - NavigationView _navView = NavigationRootPage.GetForElement(element).NavigationView; + NavigationView _navView = App.MainWindow.NavigationView; if (isLeftMode) { _navView.PaneDisplayMode = NavigationViewPaneDisplayMode.Auto; - Grid.SetRow(_navView, 0); } else { _navView.PaneDisplayMode = NavigationViewPaneDisplayMode.Top; - Grid.SetRow(_navView, 1); } } - } diff --git a/WinUIGallery/Helpers/ProtocolActivationClipboardHelper.cs b/WinUIGallery/Helpers/ProtocolActivationClipboardHelper.cs index 586ed1e1e..6011da495 100644 --- a/WinUIGallery/Helpers/ProtocolActivationClipboardHelper.cs +++ b/WinUIGallery/Helpers/ProtocolActivationClipboardHelper.cs @@ -50,14 +50,23 @@ public static bool ShowCopyLinkTeachingTip public static void Copy(ControlInfoDataItem item) { - var uri = new Uri($"winui3gallery://item/{item.UniqueId}", UriKind.Absolute); - ProtocolActivationClipboardHelper.Copy(uri, $"{Package.Current.DisplayName} - {item.Title} Sample"); + var uri = new Uri($"{GetAppName()}://item/{item.UniqueId}", UriKind.Absolute); + Copy(uri, $"{Package.Current.DisplayName} - {item.Title} Sample"); } public static void Copy(ControlInfoDataGroup group) { - var uri = new Uri($"winui3gallery://category/{group.UniqueId}", UriKind.Absolute); - ProtocolActivationClipboardHelper.Copy(uri, $"{Package.Current.DisplayName} - {group.Title} Samples"); + var uri = new Uri($"{GetAppName()}://category/{group.UniqueId}", UriKind.Absolute); + Copy(uri, $"{Package.Current.DisplayName} - {group.Title} Samples"); + } + + private static string GetAppName() + { +#if DEBUG + return "winui3gallerydev"; +#else + return "winui3gallery"; +#endif } private static void Copy(Uri uri, string displayName) diff --git a/WinUIGallery/Helpers/TitleBarHelper.cs b/WinUIGallery/Helpers/TitleBarHelper.cs index c031867a7..5b26e12cc 100644 --- a/WinUIGallery/Helpers/TitleBarHelper.cs +++ b/WinUIGallery/Helpers/TitleBarHelper.cs @@ -6,11 +6,11 @@ namespace WinUIGallery.Helpers; internal class TitleBarHelper { - // workaround as Appwindow titlebar doesn't update caption button colors correctly when changed while app is running + // workaround as AppWindow TitleBar doesn't update caption button colors correctly when changed while app is running // https://task.ms/44172495 public static Windows.UI.Color ApplySystemThemeToCaptionButtons(Window window) { - var frame = (Application.Current as WinUIGallery.App).GetRootFrame() as FrameworkElement; + var frame = App.MainWindow.GetRootFrame() as FrameworkElement; Windows.UI.Color color; if (frame.ActualTheme == ElementTheme.Dark) { @@ -20,7 +20,7 @@ public static Windows.UI.Color ApplySystemThemeToCaptionButtons(Window window) { color = Colors.Black; } - SetCaptionButtonColors(window,color); + SetCaptionButtonColors(window, color); return color; } diff --git a/WinUIGallery/Pages/NavigationRootPage.xaml b/WinUIGallery/MainWindow.xaml similarity index 75% rename from WinUIGallery/Pages/NavigationRootPage.xaml rename to WinUIGallery/MainWindow.xaml index b4dc3d3ff..6a273839d 100644 --- a/WinUIGallery/Pages/NavigationRootPage.xaml +++ b/WinUIGallery/MainWindow.xaml @@ -1,63 +1,58 @@ - - + - - - - - - + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:local="using:WinUIGallery" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:pages="using:WinUIGallery.Pages" + Title="MainWindow" + mc:Ignorable="d"> + + + + - - - - - - - + + + + + - - - - - + x:FieldModifier="public" + KeyboardAcceleratorPlacementMode="Hidden" + PlaceholderText="Search" + QueryIcon="Find" + QuerySubmitted="OnControlsSearchBoxQuerySubmitted" + TextChanged="OnControlsSearchBoxTextChanged"> + + + + + + + + diff --git a/WinUIGallery/WinUIGallery.csproj b/WinUIGallery/WinUIGallery.csproj index b88018f2a..48fa8b75b 100644 --- a/WinUIGallery/WinUIGallery.csproj +++ b/WinUIGallery/WinUIGallery.csproj @@ -311,6 +311,7 @@ + @@ -487,6 +488,12 @@ + + + MSBuild:Compile + + + MSBuild:Compile From 91922d738a97cc4eaa33379de8317c4bd273f999 Mon Sep 17 00:00:00 2001 From: Niels Laute Date: Wed, 12 Mar 2025 11:55:29 +0100 Subject: [PATCH 12/18] Update MainWindow.xaml.cs --- WinUIGallery/MainWindow.xaml.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/WinUIGallery/MainWindow.xaml.cs b/WinUIGallery/MainWindow.xaml.cs index 95f45db84..6f2cb1646 100644 --- a/WinUIGallery/MainWindow.xaml.cs +++ b/WinUIGallery/MainWindow.xaml.cs @@ -410,7 +410,6 @@ private void OnControlsSearchBoxQuerySubmitted(AutoSuggestBox sender, AutoSugges { Navigate(typeof(SearchResultsPage), args.QueryText); } - sender.Text = string.Empty; } public bool EnsureItemIsVisibleInNavigation(string name) From afe1332502d8be9bfeb8b9baa477841dcbaa492f Mon Sep 17 00:00:00 2001 From: Niels Laute Date: Wed, 12 Mar 2025 14:03:37 +0100 Subject: [PATCH 13/18] Remove unused usings --- WinUIGallery/Samples/ControlPages/BorderPage.xaml | 1 - WinUIGallery/Samples/ControlPages/CanvasPage.xaml | 1 - .../Samples/ControlPages/CreateMultipleWindowsPage.xaml | 1 - WinUIGallery/Samples/ControlPages/DropDownButtonPage.xaml | 2 -- WinUIGallery/Samples/ControlPages/GridPage.xaml | 1 - WinUIGallery/Samples/ControlPages/LinePage.xaml | 1 - WinUIGallery/Samples/ControlPages/MenuBarPage.xaml | 2 -- WinUIGallery/Samples/ControlPages/ShapePage.xaml | 3 --- WinUIGallery/Samples/ControlPages/TimePickerPage.xaml | 1 - 9 files changed, 13 deletions(-) diff --git a/WinUIGallery/Samples/ControlPages/BorderPage.xaml b/WinUIGallery/Samples/ControlPages/BorderPage.xaml index bb2c99009..13e7cadac 100644 --- a/WinUIGallery/Samples/ControlPages/BorderPage.xaml +++ b/WinUIGallery/Samples/ControlPages/BorderPage.xaml @@ -13,7 +13,6 @@ x:Class="WinUIGallery.ControlPages.BorderPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:common="using:WinUIGallery.Common" xmlns:controls="using:WinUIGallery.Controls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" diff --git a/WinUIGallery/Samples/ControlPages/CanvasPage.xaml b/WinUIGallery/Samples/ControlPages/CanvasPage.xaml index e5d0f60ab..eee00b352 100644 --- a/WinUIGallery/Samples/ControlPages/CanvasPage.xaml +++ b/WinUIGallery/Samples/ControlPages/CanvasPage.xaml @@ -13,7 +13,6 @@ x:Class="WinUIGallery.ControlPages.CanvasPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:common="using:WinUIGallery.Common" xmlns:controls="using:WinUIGallery.Controls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" diff --git a/WinUIGallery/Samples/ControlPages/CreateMultipleWindowsPage.xaml b/WinUIGallery/Samples/ControlPages/CreateMultipleWindowsPage.xaml index dadc493c2..d8a561407 100644 --- a/WinUIGallery/Samples/ControlPages/CreateMultipleWindowsPage.xaml +++ b/WinUIGallery/Samples/ControlPages/CreateMultipleWindowsPage.xaml @@ -15,7 +15,6 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="using:WinUIGallery.Controls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:data="using:WinUIGallery.Data" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"> diff --git a/WinUIGallery/Samples/ControlPages/DropDownButtonPage.xaml b/WinUIGallery/Samples/ControlPages/DropDownButtonPage.xaml index 2938d7f0b..426c9498c 100644 --- a/WinUIGallery/Samples/ControlPages/DropDownButtonPage.xaml +++ b/WinUIGallery/Samples/ControlPages/DropDownButtonPage.xaml @@ -2,10 +2,8 @@ x:Class="WinUIGallery.ControlPages.DropDownButtonPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:common="using:WinUIGallery.Common" xmlns:controls="using:WinUIGallery.Controls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:data="using:WinUIGallery.Data" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"> diff --git a/WinUIGallery/Samples/ControlPages/GridPage.xaml b/WinUIGallery/Samples/ControlPages/GridPage.xaml index 17245b860..27ec0269e 100644 --- a/WinUIGallery/Samples/ControlPages/GridPage.xaml +++ b/WinUIGallery/Samples/ControlPages/GridPage.xaml @@ -13,7 +13,6 @@ x:Class="WinUIGallery.ControlPages.GridPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:common="using:WinUIGallery.Common" xmlns:controls="using:WinUIGallery.Controls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" diff --git a/WinUIGallery/Samples/ControlPages/LinePage.xaml b/WinUIGallery/Samples/ControlPages/LinePage.xaml index c4cae3d64..d7576ce36 100644 --- a/WinUIGallery/Samples/ControlPages/LinePage.xaml +++ b/WinUIGallery/Samples/ControlPages/LinePage.xaml @@ -15,7 +15,6 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="using:WinUIGallery.Controls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:data="using:WinUIGallery.Data" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:wuxdata="using:Microsoft.UI.Xaml.Data" mc:Ignorable="d"> diff --git a/WinUIGallery/Samples/ControlPages/MenuBarPage.xaml b/WinUIGallery/Samples/ControlPages/MenuBarPage.xaml index ea4d6416a..5aca25c32 100644 --- a/WinUIGallery/Samples/ControlPages/MenuBarPage.xaml +++ b/WinUIGallery/Samples/ControlPages/MenuBarPage.xaml @@ -2,10 +2,8 @@ x:Class="WinUIGallery.ControlPages.MenuBarPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:common="using:WinUIGallery.Common" xmlns:controls="using:WinUIGallery.Controls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:data="using:WinUIGallery.Data" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"> diff --git a/WinUIGallery/Samples/ControlPages/ShapePage.xaml b/WinUIGallery/Samples/ControlPages/ShapePage.xaml index 9fefcc5bd..a1e8cf137 100644 --- a/WinUIGallery/Samples/ControlPages/ShapePage.xaml +++ b/WinUIGallery/Samples/ControlPages/ShapePage.xaml @@ -15,14 +15,11 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="using:WinUIGallery.Controls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:data="using:WinUIGallery.Data" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:wuxdata="using:Microsoft.UI.Xaml.Data" mc:Ignorable="d"> - - diff --git a/WinUIGallery/Samples/ControlPages/TimePickerPage.xaml b/WinUIGallery/Samples/ControlPages/TimePickerPage.xaml index f478a1fb7..e96e367c5 100644 --- a/WinUIGallery/Samples/ControlPages/TimePickerPage.xaml +++ b/WinUIGallery/Samples/ControlPages/TimePickerPage.xaml @@ -13,7 +13,6 @@ x:Class="WinUIGallery.ControlPages.TimePickerPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:common="using:WinUIGallery.Common" xmlns:controls="using:WinUIGallery.Controls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" From 6c4637149aa920eebac12bbc528c82268e54e571 Mon Sep 17 00:00:00 2001 From: Niels Laute Date: Wed, 12 Mar 2025 14:07:56 +0100 Subject: [PATCH 14/18] Revert back horizontal stretch for TitleBar --- WinUIGallery/MainWindow.xaml | 2 +- WinUIGallery/MainWindow.xaml.cs | 2 +- WinUIGallery/Styles/TitleBar.xaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/WinUIGallery/MainWindow.xaml b/WinUIGallery/MainWindow.xaml index d81276396..b191617d7 100644 --- a/WinUIGallery/MainWindow.xaml +++ b/WinUIGallery/MainWindow.xaml @@ -32,7 +32,7 @@ From ac20066e44aff82cb0e86048a30e68a41f87149c Mon Sep 17 00:00:00 2001 From: Niels Laute Date: Wed, 12 Mar 2025 15:03:27 +0100 Subject: [PATCH 15/18] Adding TitleBar samples --- .../Samples/ControlPages/TitleBarPage.xaml | 350 +++++++----------- .../Samples/ControlPages/TitleBarPage.xaml.cs | 224 +---------- .../Samples/Data/ControlInfoData.json | 10 +- .../Samples/SamplePages/TitleBarWindow.xaml | 71 ++++ .../SamplePages/TitleBarWindow.xaml.cs | 40 ++ WinUIGallery/WinUIGallery.csproj | 7 + 6 files changed, 264 insertions(+), 438 deletions(-) create mode 100644 WinUIGallery/Samples/SamplePages/TitleBarWindow.xaml create mode 100644 WinUIGallery/Samples/SamplePages/TitleBarWindow.xaml.cs diff --git a/WinUIGallery/Samples/ControlPages/TitleBarPage.xaml b/WinUIGallery/Samples/ControlPages/TitleBarPage.xaml index 88339cb42..5889b5821 100644 --- a/WinUIGallery/Samples/ControlPages/TitleBarPage.xaml +++ b/WinUIGallery/Samples/ControlPages/TitleBarPage.xaml @@ -19,234 +19,158 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:wuxdata="using:Microsoft.UI.Xaml.Data" mc:Ignorable="d"> + + + + To fully customize the title bar area without using the TitleBar control, visit + Microsoft Learn + . + + - - 32 - - - - - - TitleBar control is now available in Experimental - ! - Preview samples for TitleBar at feature/TitleBarExperimental - - - - - - - - - - - WinUI provides a default titlebar in such cases where the user doesn't explicitly provide a uielement, for setting the titlebar. The system titlebar (Windows-provided titlebar) disappears and client area content is extended to non client area. - In this default case, entire non client region (titlebar region) get system titlebar behaviors like drag regions, system menu on context click etc. - This is the recommended way of using TitleBar apis and covers most common scenarios. - It can be applied by just calling ExtendsContentIntoTitleBar api. This internally calls SetTitleBar api with null argument and provides the default case. - Use the button below to toggle between system titlebar and default custom titlebar. - - - - - - - diff --git a/WinUIGallery/Samples/ControlPages/TitleBarPage.xaml.cs b/WinUIGallery/Samples/ControlPages/TitleBarPage.xaml.cs index a81772f8e..5a576b881 100644 --- a/WinUIGallery/Samples/ControlPages/TitleBarPage.xaml.cs +++ b/WinUIGallery/Samples/ControlPages/TitleBarPage.xaml.cs @@ -7,238 +7,22 @@ // PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. // //********************************************************* -using WinUIGallery.Helpers; -using Microsoft.UI; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; -using Microsoft.UI.Xaml.Media; -using Microsoft.UI.Xaml.Shapes; -using System.Threading.Tasks; -using Microsoft.UI.Windowing; -using Microsoft.UI.Xaml.Navigation; -using Microsoft.UI.Input; -using Windows.Foundation; -using System; +using WinUIGallery.Samples.SamplePages; namespace WinUIGallery.ControlPages; public sealed partial class TitleBarPage : Page { - private Windows.UI.Color currentBgColor = Colors.Transparent; - private Windows.UI.Color currentFgColor = ThemeHelper.ActualTheme == ElementTheme.Dark ? Colors.White : Colors.Black; - private bool sizeChangedEventHandlerAdded = false; - public TitleBarPage() { this.InitializeComponent(); - Loaded += (object sender, RoutedEventArgs e) => - { - (sender as TitleBarPage).UpdateTitleBarColor(); - UpdateButtonText(); - }; - } - - protected override void OnNavigatedFrom(NavigationEventArgs e) - { - ResetTitlebarSettings(); - } - - private void SetTitleBar(bool forceCustomTitlebar = false) - { - var window = WindowHelper.GetWindowForElement(this as UIElement); - var titleBarElement = UIHelper.FindElementByName(this as UIElement, "AppTitleBar"); - if (forceCustomTitlebar || !window.ExtendsContentIntoTitleBar) - { - titleBarElement.Visibility = Visibility.Visible; - window.ExtendsContentIntoTitleBar = true; - window.SetTitleBar(titleBarElement); - TitleBarHelper.SetCaptionButtonBackgroundColors(window, Colors.Transparent); - } - else - { - titleBarElement.Visibility = Visibility.Collapsed; - window.ExtendsContentIntoTitleBar = false; - TitleBarHelper.SetCaptionButtonBackgroundColors(window, null); - } - UpdateButtonText(); - UpdateTitleBarColor(); - } - - private void ResetTitlebarSettings() - { - var window = WindowHelper.GetWindowForElement(this as UIElement); - SetTitleBar(forceCustomTitlebar: true); - ClearClickThruRegions(); - var txtBoxNonClientArea = UIHelper.FindElementByName(this as UIElement, "AppTitleBarTextBox") as FrameworkElement; - txtBoxNonClientArea.Visibility = Visibility.Collapsed; - addInteractiveElements.Content = "Add interactive control to titlebar"; - } - - private void SetClickThruRegions(Windows.Graphics.RectInt32[] rects) - { - var window = WindowHelper.GetWindowForElement(this as UIElement); - var nonClientInputSrc = InputNonClientPointerSource.GetForWindowId(window.AppWindow.Id); - nonClientInputSrc.SetRegionRects(NonClientRegionKind.Passthrough, rects); - } - - private void ClearClickThruRegions() - { - var window = WindowHelper.GetWindowForElement(this as UIElement); - var noninputsrc = InputNonClientPointerSource.GetForWindowId(window.AppWindow.Id); - noninputsrc.ClearRegionRects(NonClientRegionKind.Passthrough); - } - - public void UpdateButtonText() - { - var window = WindowHelper.GetWindowForElement(this as UIElement); - - if (window.ExtendsContentIntoTitleBar) - { - customTitleBar.Content = "Reset to System TitleBar"; - defaultTitleBar.Content = "Reset to System TitleBar"; - } - else - { - customTitleBar.Content = "Set Custom TitleBar"; - defaultTitleBar.Content = "Set Default Custom TitleBar"; - } - } - private void BgGridView_ItemClick(object sender, ItemClickEventArgs e) + private void CreateTitleBarWindowClick(object sender, RoutedEventArgs e) { - var rect = (Rectangle)e.ClickedItem; - var color = ((SolidColorBrush)rect.Fill).Color; - BackgroundColorElement.Background = new SolidColorBrush(color); - - currentBgColor = color; - UpdateTitleBarColor(); - - // Delay required to circumvent GridView bug: https://github.com/microsoft/microsoft-ui-xaml/issues/6350 - Task.Delay(10).ContinueWith(_ => myBgColorButton.Flyout.Hide(), TaskScheduler.FromCurrentSynchronizationContext()); + TitleBarWindow titleBarWindow = new TitleBarWindow(); + titleBarWindow.Activate(); } - - private void FgGridView_ItemClick(object sender, ItemClickEventArgs e) - { - var rect = (Rectangle)e.ClickedItem; - var color = ((SolidColorBrush)rect.Fill).Color; - - ForegroundColorElement.Background = new SolidColorBrush(color); - - currentFgColor = color; - UpdateTitleBarColor(); - - // Delay required to circumvent GridView bug: https://github.com/microsoft/microsoft-ui-xaml/issues/6350 - Task.Delay(10).ContinueWith(_ => myFgColorButton.Flyout.Hide(), TaskScheduler.FromCurrentSynchronizationContext()); - } - - - public void UpdateTitleBarColor() - { - var window = WindowHelper.GetWindowForElement(this); - var titleBarElement = UIHelper.FindElementByName(this, "AppTitleBar"); - var titleBarAppNameElement = UIHelper.FindElementByName(this, "AppTitle"); - - (titleBarElement as Border).Background = new SolidColorBrush(currentBgColor); // Changing titlebar uielement's color. - - if (currentFgColor != Colors.Transparent) - { - (titleBarAppNameElement as TextBlock).Foreground = new SolidColorBrush(currentFgColor); - } - else - { - (titleBarAppNameElement as TextBlock).Foreground = Application.Current.Resources["TextFillColorPrimaryBrush"] as SolidColorBrush; - } - - TitleBarHelper.SetCaptionButtonColors(window, currentFgColor); - - if (currentBgColor == Colors.Transparent) - { - // If the current background is null, we want to revert to the default titlebar which is achieved using null as color. - TitleBarHelper.SetBackgroundColor(window, null); - } - else - { - TitleBarHelper.SetBackgroundColor(window, currentBgColor); - } - - TitleBarHelper.SetForegroundColor(window, currentFgColor); - } - - private void customTitleBar_Click(object sender, RoutedEventArgs e) - { - SetTitleBar(); - // announce visual change to automation - UIHelper.AnnounceActionForAccessibility(sender as UIElement, "TitleBar size and width changed", "TitleBarChangedNotificationActivityId"); - } - private void defaultTitleBar_Click(object sender, RoutedEventArgs e) - { - SetTitleBar(); - - // announce visual change to automation - UIHelper.AnnounceActionForAccessibility(sender as UIElement, "TitleBar size and width changed", "TitleBarChangedNotificationActivityId"); - } - - private void setTxtBoxAsPasthrough(FrameworkElement txtBoxNonClientArea) - { - GeneralTransform transformTxtBox = txtBoxNonClientArea.TransformToVisual(null); - Rect bounds = transformTxtBox.TransformBounds(new Rect(0, 0, txtBoxNonClientArea.ActualWidth, txtBoxNonClientArea.ActualHeight)); - - var scale = WindowHelper.GetRasterizationScaleForElement(this); - - var transparentRect = new Windows.Graphics.RectInt32( - _X: (int)Math.Round(bounds.X * scale), - _Y: (int)Math.Round(bounds.Y * scale), - _Width: (int)Math.Round(bounds.Width * scale), - _Height: (int)Math.Round(bounds.Height * scale) - ); - var rectArr = new Windows.Graphics.RectInt32[] { transparentRect }; - SetClickThruRegions(rectArr); - } - - private void TitleBarHeightComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) - { - var selectedHeight = titlebarHeight.SelectedItem.ToString(); - var window = WindowHelper.GetWindowForElement(this); - - if (selectedHeight != null && window != null && window.ExtendsContentIntoTitleBar) - { - window.AppWindow.TitleBar.PreferredHeightOption = EnumHelper.GetEnum(selectedHeight); - } - } - - private void AddInteractiveElements_Click(object sender, RoutedEventArgs e) - { - var txtBoxNonClientArea = UIHelper.FindElementByName(sender as UIElement, "AppTitleBarTextBox") as FrameworkElement; - - if (txtBoxNonClientArea.Visibility == Visibility.Visible) - { - ResetTitlebarSettings(); - } - else - { - addInteractiveElements.Content = "Remove interactive control from titlebar"; - txtBoxNonClientArea.Visibility = Visibility.Visible; - if (sizeChangedEventHandlerAdded) - { - setTxtBoxAsPasthrough(txtBoxNonClientArea); - } - else - { - sizeChangedEventHandlerAdded = true; - // run this code when textbox has been made visible and its actual width and height has been calculated - txtBoxNonClientArea.SizeChanged += (object sender, SizeChangedEventArgs e) => - { - if (txtBoxNonClientArea.Visibility != Visibility.Collapsed) - { - setTxtBoxAsPasthrough(txtBoxNonClientArea); - } - }; - } - - // announce visual change to automation - UIHelper.AnnounceActionForAccessibility(sender as UIElement, "TitleBar size and width changed", "TitleBarChangedNotificationActivityId"); - } - } - } diff --git a/WinUIGallery/Samples/Data/ControlInfoData.json b/WinUIGallery/Samples/Data/ControlInfoData.json index 3bcc0209d..2f41ff9fc 100644 --- a/WinUIGallery/Samples/Data/ControlInfoData.json +++ b/WinUIGallery/Samples/Data/ControlInfoData.json @@ -3625,17 +3625,17 @@ "ApiNamespace": "Microsoft.UI.Xaml", "Subtitle": "An example showing a custom UIElement used as the titlebar for the app's window.", "ImagePath": "ms-appx:///Assets/ControlImages/TitleBar.png", - "Description": "This sample shows how to use a custom titlebar for the app's window. There are 2 ways of doing it: using default titlebar and setting an UIElement as a custom titlebar.", + "Description": "The TitleBar control provides a simple way to create a modern titlebar UX with interactive content.", "Content": "

Look at the TitleBarPage.xaml file in Visual Studio to see the full code for this page.

", "IsUpdated": true, "Docs": [ { - "Title": "TitleBar - API", - "Uri": "https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.window.extendscontentintotitlebar" + "Title": "Title bar customization", + "Uri": "https://learn.microsoft.com/windows/apps/develop/title-bar" }, { - "Title": "Guidelines", - "Uri": "https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.window" + "Title": "Titl bar - design guidelines", + "Uri": "https://learn.microsoft.com/windows/apps/design/basics/titlebar-design" } ], "RelatedControls": [ diff --git a/WinUIGallery/Samples/SamplePages/TitleBarWindow.xaml b/WinUIGallery/Samples/SamplePages/TitleBarWindow.xaml new file mode 100644 index 000000000..47a2adcf7 --- /dev/null +++ b/WinUIGallery/Samples/SamplePages/TitleBarWindow.xaml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/WinUIGallery/Samples/SamplePages/TitleBarWindow.xaml.cs b/WinUIGallery/Samples/SamplePages/TitleBarWindow.xaml.cs new file mode 100644 index 000000000..6f1e4584e --- /dev/null +++ b/WinUIGallery/Samples/SamplePages/TitleBarWindow.xaml.cs @@ -0,0 +1,40 @@ +using System; +using System.Linq; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; + +namespace WinUIGallery.Samples.SamplePages; + +public sealed partial class TitleBarWindow : Window +{ + public TitleBarWindow() + { + this.InitializeComponent(); + this.ExtendsContentIntoTitleBar = true; // Extend the content into the title bar and hide the default title bar + this.SetTitleBar(titleBar); // Set the custom title bar + navView.SelectedItem = navView.MenuItems.OfType().First(); + } + + private void TitleBar_PaneToggleRequested(TitleBar sender, object args) + { + navView.IsPaneOpen = !navView.IsPaneOpen; + } + + private void TitleBar_BackRequested(TitleBar sender, object args) + { + navFrame.GoBack(); + } + + private void navView_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args) + { + var selectedItem = (NavigationViewItem)args.SelectedItem; + if (selectedItem != null) + { + string selectedItemTag = ((string)selectedItem.Tag); + sender.Header = "Sample Page " + selectedItemTag.Substring(selectedItemTag.Length - 1); + string pageName = "WinUIGallery.SamplePages." + selectedItemTag; + Type pageType = Type.GetType(pageName); + navFrame.Navigate(pageType); + } + } +} diff --git a/WinUIGallery/WinUIGallery.csproj b/WinUIGallery/WinUIGallery.csproj index 48fa8b75b..43d848ba0 100644 --- a/WinUIGallery/WinUIGallery.csproj +++ b/WinUIGallery/WinUIGallery.csproj @@ -306,6 +306,7 @@ + @@ -488,6 +489,12 @@ + + + MSBuild:Compile + + + MSBuild:Compile From a62f63cffced877602c98469400018e82bf76ced Mon Sep 17 00:00:00 2001 From: Niels Laute Date: Wed, 12 Mar 2025 15:04:55 +0100 Subject: [PATCH 16/18] Update TitleBarWindow.xaml --- WinUIGallery/Samples/SamplePages/TitleBarWindow.xaml | 1 + 1 file changed, 1 insertion(+) diff --git a/WinUIGallery/Samples/SamplePages/TitleBarWindow.xaml b/WinUIGallery/Samples/SamplePages/TitleBarWindow.xaml index 47a2adcf7..9422d4335 100644 --- a/WinUIGallery/Samples/SamplePages/TitleBarWindow.xaml +++ b/WinUIGallery/Samples/SamplePages/TitleBarWindow.xaml @@ -46,6 +46,7 @@ Grid.Row="1" IsBackButtonVisible="Collapsed" IsPaneToggleButtonVisible="False" + IsSettingsVisible="False" SelectionChanged="navView_SelectionChanged"> Date: Wed, 12 Mar 2025 16:36:07 +0100 Subject: [PATCH 17/18] TitleBarHeightOption Co-authored-by: Zakaria Tahri | Shade <101801384+Zakariathr22@users.noreply.github.com> --- WinUIGallery/Samples/SamplePages/TitleBarWindow.xaml.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/WinUIGallery/Samples/SamplePages/TitleBarWindow.xaml.cs b/WinUIGallery/Samples/SamplePages/TitleBarWindow.xaml.cs index 6f1e4584e..b89bebd06 100644 --- a/WinUIGallery/Samples/SamplePages/TitleBarWindow.xaml.cs +++ b/WinUIGallery/Samples/SamplePages/TitleBarWindow.xaml.cs @@ -11,6 +11,7 @@ public TitleBarWindow() { this.InitializeComponent(); this.ExtendsContentIntoTitleBar = true; // Extend the content into the title bar and hide the default title bar + this.AppWindow.TitleBar.PreferredHeightOption = Microsoft.UI.Windowing.TitleBarHeightOption.Tall; this.SetTitleBar(titleBar); // Set the custom title bar navView.SelectedItem = navView.MenuItems.OfType().First(); } From fe8c29df01137ad143e012026c65372db5dbe5f5 Mon Sep 17 00:00:00 2001 From: Niels Laute Date: Wed, 12 Mar 2025 16:37:17 +0100 Subject: [PATCH 18/18] Update WinUIGallery/Samples/Data/ControlInfoData.json Co-authored-by: Zakaria Tahri | Shade <101801384+Zakariathr22@users.noreply.github.com> --- WinUIGallery/Samples/Data/ControlInfoData.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WinUIGallery/Samples/Data/ControlInfoData.json b/WinUIGallery/Samples/Data/ControlInfoData.json index 2f41ff9fc..8090c96d7 100644 --- a/WinUIGallery/Samples/Data/ControlInfoData.json +++ b/WinUIGallery/Samples/Data/ControlInfoData.json @@ -3622,7 +3622,7 @@ { "UniqueId": "TitleBar", "Title": "TitleBar", - "ApiNamespace": "Microsoft.UI.Xaml", + "ApiNamespace": "Microsoft.UI.Xaml.Controls", "Subtitle": "An example showing a custom UIElement used as the titlebar for the app's window.", "ImagePath": "ms-appx:///Assets/ControlImages/TitleBar.png", "Description": "The TitleBar control provides a simple way to create a modern titlebar UX with interactive content.",