From 61834731910b7fb13d795c1a405c7452f593e6f5 Mon Sep 17 00:00:00 2001 From: Jesse Collins Date: Wed, 9 Sep 2026 15:09:10 -0700 Subject: [PATCH 1/7] Checkpoint --- WinUIGallery/App.xaml.cs | 35 +++++++++++++++++++++++++++++++++ WinUIGallery/MainWindow.xaml.cs | 9 +++++++-- standalone.props | 5 ++++- 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/WinUIGallery/App.xaml.cs b/WinUIGallery/App.xaml.cs index 6faf0081c..3d835fc02 100644 --- a/WinUIGallery/App.xaml.cs +++ b/WinUIGallery/App.xaml.cs @@ -7,6 +7,7 @@ using Microsoft.Windows.AppNotifications; using Microsoft.Windows.AppNotifications.Builder; using Microsoft.Windows.BadgeNotifications; +using Microsoft.Windows.Storage; using System; using System.Collections.Generic; using System.Diagnostics; @@ -45,6 +46,10 @@ protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs ar IdleSynchronizer.Init(); MainWindow = new MainWindow(); + + //TODO: Only call this if we're building with an exp version of WinAppSDK + PersistMainWindowSize(); + WindowHelper.TrackWindow(MainWindow); #if DEBUG @@ -91,6 +96,36 @@ protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs ar }; } +// TODO: Only build this function if we're using an experimental WinAppSDK + private void PersistMainWindowSize() + { + ApplicationData appData = ApplicationData.GetDefault(); + + string containerName = "MainWindow_Settings"; + string valueName = "SavedSize"; + + var settingsContainer = appData.LocalSettings.Containers[containerName]; + if (settingsContainer != null) + { + if (settingsContainer.Values[valueName] is Windows.Foundation.Size savedSize) + { + MainWindow.Width = savedSize.Width; + MainWindow.Height = savedSize.Height; + } + } + + Windows.Foundation.Size lastSize = new Windows.Foundation.Size(MainWindow.Width, MainWindow.Height); + + MainWindow.SizeChanged += (s, e) => { + lastSize = new Windows.Foundation.Size(MainWindow.Width, MainWindow.Height); + }; + + MainWindow.Closed += (s, e) => { + ApplicationDataContainer appDataContainer = appData.LocalSettings.CreateContainer(containerName, ApplicationDataCreateDisposition.Always); + appDataContainer.Values[valueName] = lastSize; + }; + } + private void DebugSettings_BindingFailed(object sender, BindingFailedEventArgs e) { // Ignore the exception from NonExistentProperty in BindingPage.xaml, diff --git a/WinUIGallery/MainWindow.xaml.cs b/WinUIGallery/MainWindow.xaml.cs index 439c55342..4065665c7 100644 --- a/WinUIGallery/MainWindow.xaml.cs +++ b/WinUIGallery/MainWindow.xaml.cs @@ -75,8 +75,9 @@ private void AdjustNavigationViewMargin(bool? force = null) private void RootGrid_Loaded(object sender, RoutedEventArgs e) { + // TODO: We only need to do this when MinWidth/Height aren't available. Today they're only in the experimental WinAppSDK. // We need to set the minimum size here because the XamlRoot is not available in the constructor. - WindowHelper.SetWindowMinSize(this, 640, 500); + //WindowHelper.SetWindowMinSize(this, 640, 500); if (sender is FrameworkElement rootGrid && rootGrid.XamlRoot is not null) { @@ -111,7 +112,7 @@ private void RootGrid_PointerPressed(object sender, PointerRoutedEventArgs e) private void RootGridXamlRoot_Changed(XamlRoot sender, XamlRootChangedEventArgs args) { - WindowHelper.SetWindowMinSize(this, 640, 500); + //WindowHelper.SetWindowMinSize(this, 640, 500); } private void SetWindowProperties() @@ -126,6 +127,10 @@ private void SetWindowProperties() this.SetTitleBar(titleBar); this.AppWindow.SetIcon("Assets/Tiles/GalleryIcon.ico"); this.AppWindow.TitleBar.PreferredHeightOption = TitleBarHeightOption.Tall; + + //TODO: Only use MinWidth/Height when WinAppSDK is experimental + this.MinWidth = 640; + this.MinHeight = 500; } private void OnPaneDisplayModeChanged(NavigationView sender, NavigationViewDisplayModeChangedEventArgs args) diff --git a/standalone.props b/standalone.props index 29c0a029c..6b8aabdea 100644 --- a/standalone.props +++ b/standalone.props @@ -2,7 +2,10 @@ 10.0.22621.42 - 2.4.0 + 2.4.0 + 2.4.1-experimental + $(WindowsAppSdkExperimentalPackageVersion) + $(WindowsAppSdkStablePackageVersion) 6.2.11 1.4.0 2.0.15 From 67dbe3d13c9384fe2e8cad184d5233d91d94c60c Mon Sep 17 00:00:00 2001 From: Jesse Collins Date: Fri, 11 Sep 2026 10:00:00 -0700 Subject: [PATCH 2/7] Use experimental self-contained WinAppSDK and window sizing APIs Target one experimental SDK across normal configurations, bundle its runtime, and migrate appropriate samples to Window sizing properties. Keep AppWindow-focused examples unchanged, fix self-contained version reporting, and remove obsolete sizing helpers. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- README.md | 6 ++ WinUIGallery/App.xaml.cs | 35 -------- WinUIGallery/Helpers/NativeMethods.cs | 23 ----- WinUIGallery/Helpers/VersionHelper.cs | 8 +- WinUIGallery/Helpers/Win32WindowHelper.cs | 90 ------------------- WinUIGallery/Helpers/WindowHelper.cs | 28 ------ WinUIGallery/MainWindow.xaml.cs | 55 ++++++++---- WinUIGallery/NativeMethods.txt | 1 - .../TabViewWindowingSamplePage.xaml.cs | 4 +- .../AppNotification/AppNotificationPage.xaml | 27 ------ ...pleWindowsCreateSingleThreadedMultiple.txt | 4 +- .../CreateMultipleWindowsPage.xaml.cs | 5 +- .../SampleCode/Window/CreateWindowSample1.txt | 4 +- WinUIGallery/WinUIGallery.csproj | 8 +- standalone.props | 5 +- .../VersionHelperTests.cs | 25 ++++++ .../WinUIGallery.UnitTests.csproj | 1 + 17 files changed, 92 insertions(+), 237 deletions(-) delete mode 100644 WinUIGallery/Helpers/Win32WindowHelper.cs create mode 100644 tests/WinUIGallery.UnitTests/VersionHelperTests.cs diff --git a/README.md b/README.md index 5740bc3d7..fabf855d0 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,12 @@ git clone https://github.com/microsoft/WinUI-Gallery.git Ensure that the `WinUIGallery` project is set as the startup project in Visual Studio. +Gallery uses an experimental Windows App SDK to demonstrate upcoming features. +Use the normal `Debug` or `Release` configuration; the SDK version is pinned in +`standalone.props`. The runtime is bundled with the app (self-contained deployment) +instead of referencing a shared Windows App SDK framework package. Experimental +APIs can change or be removed before a stable release. + > [!WARNING] > Try deleting [`nuget.config`](nuget.config) and building again if you get the following build error: > > Assets file 'C:\Users\\...\source\repos\WinUI-Gallery\WinUIGallery\obj\WinUIGallery\project.assets.json' not found. Run a NuGet package restore to generate this file. diff --git a/WinUIGallery/App.xaml.cs b/WinUIGallery/App.xaml.cs index 3d835fc02..6faf0081c 100644 --- a/WinUIGallery/App.xaml.cs +++ b/WinUIGallery/App.xaml.cs @@ -7,7 +7,6 @@ using Microsoft.Windows.AppNotifications; using Microsoft.Windows.AppNotifications.Builder; using Microsoft.Windows.BadgeNotifications; -using Microsoft.Windows.Storage; using System; using System.Collections.Generic; using System.Diagnostics; @@ -46,10 +45,6 @@ protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs ar IdleSynchronizer.Init(); MainWindow = new MainWindow(); - - //TODO: Only call this if we're building with an exp version of WinAppSDK - PersistMainWindowSize(); - WindowHelper.TrackWindow(MainWindow); #if DEBUG @@ -96,36 +91,6 @@ protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs ar }; } -// TODO: Only build this function if we're using an experimental WinAppSDK - private void PersistMainWindowSize() - { - ApplicationData appData = ApplicationData.GetDefault(); - - string containerName = "MainWindow_Settings"; - string valueName = "SavedSize"; - - var settingsContainer = appData.LocalSettings.Containers[containerName]; - if (settingsContainer != null) - { - if (settingsContainer.Values[valueName] is Windows.Foundation.Size savedSize) - { - MainWindow.Width = savedSize.Width; - MainWindow.Height = savedSize.Height; - } - } - - Windows.Foundation.Size lastSize = new Windows.Foundation.Size(MainWindow.Width, MainWindow.Height); - - MainWindow.SizeChanged += (s, e) => { - lastSize = new Windows.Foundation.Size(MainWindow.Width, MainWindow.Height); - }; - - MainWindow.Closed += (s, e) => { - ApplicationDataContainer appDataContainer = appData.LocalSettings.CreateContainer(containerName, ApplicationDataCreateDisposition.Always); - appDataContainer.Values[valueName] = lastSize; - }; - } - private void DebugSettings_BindingFailed(object sender, BindingFailedEventArgs e) { // Ignore the exception from NonExistentProperty in BindingPage.xaml, diff --git a/WinUIGallery/Helpers/NativeMethods.cs b/WinUIGallery/Helpers/NativeMethods.cs index 87b87db4f..77c0040bf 100644 --- a/WinUIGallery/Helpers/NativeMethods.cs +++ b/WinUIGallery/Helpers/NativeMethods.cs @@ -9,22 +9,12 @@ namespace WinUIGallery.Helpers; internal partial class NativeMethods { - [DllImport("user32.dll", EntryPoint = "SetWindowLong")] - internal static extern int SetWindowLong32(IntPtr hWnd, WindowLongIndexFlags nIndex, IntPtr newProc); - - [DllImport("user32.dll", EntryPoint = "SetWindowLongPtr")] - internal static extern IntPtr SetWindowLongPtr64(IntPtr hWnd, WindowLongIndexFlags nIndex, IntPtr newProc); - [DllImport("User32.dll", CharSet = CharSet.Auto, EntryPoint = "SetWindowLongPtr")] internal static extern IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr dwNewLong); [DllImport("User32.dll", CharSet = CharSet.Auto, EntryPoint = "SetWindowLong")] internal static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong); - - [DllImport("user32.dll")] - internal static extern IntPtr CallWindowProc(IntPtr lpPrevWndFunc, IntPtr hWnd, WindowMessage Msg, IntPtr wParam, IntPtr lParam); - internal unsafe static void SetWindowKeyHook() { delegate* unmanaged[Stdcall] callback = &HookCallback; @@ -56,19 +46,6 @@ internal static bool IsKeyDownHook(IntPtr lWord) return (lWord >> 30 & 1) == 0; } - internal delegate IntPtr WinProc(IntPtr hWnd, WindowMessage Msg, IntPtr wParam, IntPtr lParam); - - [Flags] - internal enum WindowLongIndexFlags : int - { - GWL_WNDPROC = -4, - } - - internal enum WindowMessage : int - { - WM_GETMINMAXINFO = 0x0024, - } - internal static bool IsAppPackaged { get; } = GetCurrentPackageName() != null; internal static string? GetCurrentPackageName() { diff --git a/WinUIGallery/Helpers/VersionHelper.cs b/WinUIGallery/Helpers/VersionHelper.cs index df1d621d9..bbdcf4007 100644 --- a/WinUIGallery/Helpers/VersionHelper.cs +++ b/WinUIGallery/Helpers/VersionHelper.cs @@ -1,14 +1,16 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using Microsoft.Windows.ApplicationModel.WindowsAppRuntime; +using Microsoft.WindowsAppSDK; namespace WinUIGallery.Helpers; + internal static partial class VersionHelper { + // Use SDK-generated version info; self-contained apps don't deploy the framework's Insights resource DLL. public static string WinAppSdkDetails => - $"Windows App SDK {ReleaseInfo.Major}.{ReleaseInfo.Minor}"; + $"Windows App SDK {Release.Major}.{Release.Minor}"; public static string WinAppSdkRuntimeDetails => - WinAppSdkDetails + $", Windows App Runtime {RuntimeInfo.AsString}"; + WinAppSdkDetails + $", Windows App Runtime {Microsoft.WindowsAppSDK.Runtime.Version.DotQuadString}"; } diff --git a/WinUIGallery/Helpers/Win32WindowHelper.cs b/WinUIGallery/Helpers/Win32WindowHelper.cs deleted file mode 100644 index faacb1161..000000000 --- a/WinUIGallery/Helpers/Win32WindowHelper.cs +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using Microsoft.UI.Xaml; -using System.Runtime.InteropServices; -using static WinUIGallery.Helpers.NativeMethods; - -namespace WinUIGallery.Helpers; - -internal partial class Win32WindowHelper -{ - private static WinProc? newWndProc = null; - private static nint oldWndProc = nint.Zero; - - private POINT? minWindowSize = null; - private POINT? maxWindowSize = null; - - private readonly Window window; - - public Win32WindowHelper(Window window) - { - this.window = window; - } - - public void SetWindowMinMaxSize(POINT? minWindowSize = null, POINT? maxWindowSize = null) - { - this.minWindowSize = minWindowSize; - this.maxWindowSize = maxWindowSize; - - var hwnd = GetWindowHandleForCurrentWindow(window); - - newWndProc = new WinProc(WndProc); - oldWndProc = SetWindowLongPtr(hwnd, WindowLongIndexFlags.GWL_WNDPROC, newWndProc); - } - - private static nint GetWindowHandleForCurrentWindow(object target) => - WinRT.Interop.WindowNative.GetWindowHandle(target); - - private nint WndProc(nint hWnd, WindowMessage Msg, nint wParam, nint lParam) - { - switch (Msg) - { - case WindowMessage.WM_GETMINMAXINFO: - var dpi = Windows.Win32.PInvoke.GetDpiForWindow(new Windows.Win32.Foundation.HWND(hWnd)); - var scalingFactor = (float)dpi / 96; - - var minMaxInfo = Marshal.PtrToStructure(lParam); - if (minWindowSize != null) - { - minMaxInfo.ptMinTrackSize.x = (int)(minWindowSize.Value.x * scalingFactor); - minMaxInfo.ptMinTrackSize.y = (int)(minWindowSize.Value.y * scalingFactor); - } - if (maxWindowSize != null) - { - minMaxInfo.ptMaxTrackSize.x = (int)(maxWindowSize.Value.x * scalingFactor); - minMaxInfo.ptMaxTrackSize.y = (int)(maxWindowSize.Value.y * scalingFactor); - } - - Marshal.StructureToPtr(minMaxInfo, lParam, true); - break; - - } - return CallWindowProc(oldWndProc, hWnd, Msg, wParam, lParam); - } - - private nint SetWindowLongPtr(nint hWnd, WindowLongIndexFlags nIndex, WinProc newProc) - { - nint funcPtr = Marshal.GetFunctionPointerForDelegate(newProc); - if (nint.Size == 8) - return SetWindowLongPtr64(hWnd, nIndex, funcPtr); - else - return new nint(SetWindowLong32(hWnd, nIndex, funcPtr)); - } - - internal struct POINT - { - public int x; - public int y; - } - - [StructLayout(LayoutKind.Sequential)] - private struct MINMAXINFO - { - public POINT ptReserved; - public POINT ptMaxSize; - public POINT ptMaxPosition; - public POINT ptMinTrackSize; - public POINT ptMaxTrackSize; - } -} diff --git a/WinUIGallery/Helpers/WindowHelper.cs b/WinUIGallery/Helpers/WindowHelper.cs index 35c819f34..8fc9035d3 100644 --- a/WinUIGallery/Helpers/WindowHelper.cs +++ b/WinUIGallery/Helpers/WindowHelper.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using Microsoft.UI.Windowing; using Microsoft.UI.Xaml; using System; using System.Collections.Generic; @@ -63,33 +62,6 @@ static public double GetRasterizationScaleForElement(UIElement element) return 0.0; } - static public void SetWindowMinSize(Window window, double width, double height) - { - if (window.Content is not FrameworkElement windowContent) - { - System.Diagnostics.Debug.WriteLine("Window content is not a FrameworkElement."); - return; - } - - if (windowContent.XamlRoot is null) - { - System.Diagnostics.Debug.WriteLine("Window content's XamlRoot is null."); - return; - } - - if (window.AppWindow.Presenter is not OverlappedPresenter presenter) - { - System.Diagnostics.Debug.WriteLine("Window's AppWindow.Presenter is not an OverlappedPresenter."); - return; - } - - var scale = windowContent.XamlRoot.RasterizationScale; - var minWidth = width * scale; - var minHeight = height * scale; - presenter.PreferredMinimumWidth = (int)minWidth; - presenter.PreferredMinimumHeight = (int)minHeight; - } - static public List ActiveWindows { get { return _activeWindows; } } static private List _activeWindows = new List(); diff --git a/WinUIGallery/MainWindow.xaml.cs b/WinUIGallery/MainWindow.xaml.cs index 4065665c7..4f2084f1d 100644 --- a/WinUIGallery/MainWindow.xaml.cs +++ b/WinUIGallery/MainWindow.xaml.cs @@ -9,6 +9,7 @@ using Microsoft.UI.Xaml.Input; using Microsoft.UI.Xaml.Media.Animation; using Microsoft.UI.Xaml.Navigation; +using Microsoft.Windows.Storage; using System; using System.Collections.Generic; using System.Linq; @@ -54,6 +55,41 @@ public MainWindow() AdjustNavigationViewMargin(force: true); AppWindow.Changed += (_, _) => AdjustNavigationViewMargin(); } + + InitializeSizePersistence(); + } + + // Use a rudimenentary persistence mechanism to save the window size between app launches. + // In the future we hope to have persistence APIs directly in WinUI/WinAppSDK. + private void InitializeSizePersistence() + { + ApplicationData appData = NativeMethods.IsAppPackaged + ? ApplicationData.GetDefault() + : ApplicationData.GetForUnpackaged(ProcessInfoHelper.Publisher, ProcessInfoHelper.ProductName); + + const string containerName = "MainWindow_Settings"; + const string valueName = "SavedSize"; + + if (appData.LocalSettings.Containers.TryGetValue(containerName, out var settingsContainer) && + settingsContainer.Values.TryGetValue(valueName, out object? value) && + value is Size savedSize) + { + Width = savedSize.Width; + Height = savedSize.Height; + } + + Size lastSize = new Size(Width, Height); + + SizeChanged += (s, e) => + { + lastSize = new Size(Width, Height); + }; + + Closed += (s, e) => + { + ApplicationDataContainer appDataContainer = appData.LocalSettings.CreateContainer(containerName, ApplicationDataCreateDisposition.Always); + appDataContainer.Values[valueName] = lastSize; + }; } // Adjusts the NavigationView margin based on the window state @@ -75,15 +111,6 @@ private void AdjustNavigationViewMargin(bool? force = null) private void RootGrid_Loaded(object sender, RoutedEventArgs e) { - // TODO: We only need to do this when MinWidth/Height aren't available. Today they're only in the experimental WinAppSDK. - // We need to set the minimum size here because the XamlRoot is not available in the constructor. - //WindowHelper.SetWindowMinSize(this, 640, 500); - - if (sender is FrameworkElement rootGrid && rootGrid.XamlRoot is not null) - { - rootGrid.XamlRoot.Changed += RootGridXamlRoot_Changed; - } - NavigationOrientationHelper.UpdateNavigationViewForElement(NavigationOrientationHelper.IsLeftMode()); TitleBarHelper.ApplySystemThemeToCaptionButtons(this, RootGrid.ActualTheme); } @@ -110,11 +137,6 @@ private void RootGrid_PointerPressed(object sender, PointerRoutedEventArgs e) } } - private void RootGridXamlRoot_Changed(XamlRoot sender, XamlRootChangedEventArgs args) - { - //WindowHelper.SetWindowMinSize(this, 640, 500); - } - private void SetWindowProperties() { #if DEBUG || DEBUG_UNPACKAGED @@ -128,9 +150,8 @@ private void SetWindowProperties() this.AppWindow.SetIcon("Assets/Tiles/GalleryIcon.ico"); this.AppWindow.TitleBar.PreferredHeightOption = TitleBarHeightOption.Tall; - //TODO: Only use MinWidth/Height when WinAppSDK is experimental - this.MinWidth = 640; - this.MinHeight = 500; + MinWidth = 640; + MinHeight = 500; } private void OnPaneDisplayModeChanged(NavigationView sender, NavigationViewDisplayModeChangedEventArgs args) diff --git a/WinUIGallery/NativeMethods.txt b/WinUIGallery/NativeMethods.txt index cd2c02982..2b899b698 100644 --- a/WinUIGallery/NativeMethods.txt +++ b/WinUIGallery/NativeMethods.txt @@ -1,7 +1,6 @@ GetCurrentPackageFullName GetModuleHandle GetDpiForWindow -CallWindowProc GetCurrentThreadId SetWindowsHookEx CallNextHookEx diff --git a/WinUIGallery/SampleSupport/SamplePages/TabViewWindowingSamplePage.xaml.cs b/WinUIGallery/SampleSupport/SamplePages/TabViewWindowingSamplePage.xaml.cs index 697d5f88c..936f55f50 100644 --- a/WinUIGallery/SampleSupport/SamplePages/TabViewWindowingSamplePage.xaml.cs +++ b/WinUIGallery/SampleSupport/SamplePages/TabViewWindowingSamplePage.xaml.cs @@ -31,8 +31,8 @@ private void TabViewWindowingSamplePage_Loaded(object sender, RoutedEventArgs e) currentWindow.SetTitleBar(CustomDragRegion); CustomDragRegion.MinWidth = 188; - // Set minimum window size using OverlappedPresenter (requires XamlRoot, so must be done after Loaded). - WindowHelper.SetWindowMinSize(currentWindow, 500, 300); + currentWindow.MinWidth = 500; + currentWindow.MinHeight = 300; } public void LoadDemoData() diff --git a/WinUIGallery/Samples/AppNotification/AppNotificationPage.xaml b/WinUIGallery/Samples/AppNotification/AppNotificationPage.xaml index e9e6c5beb..ae7f7fd9a 100644 --- a/WinUIGallery/Samples/AppNotification/AppNotificationPage.xaml +++ b/WinUIGallery/Samples/AppNotification/AppNotificationPage.xaml @@ -11,33 +11,6 @@ - - - - - - - - - - - - - - - - - - - - - - true true - true - - true + true Assets\Tiles\GalleryIcon.ico enable true @@ -82,6 +80,10 @@ + + + + Designer diff --git a/standalone.props b/standalone.props index 6b8aabdea..d3f5583e1 100644 --- a/standalone.props +++ b/standalone.props @@ -2,10 +2,7 @@ 10.0.22621.42 - 2.4.0 - 2.4.1-experimental - $(WindowsAppSdkExperimentalPackageVersion) - $(WindowsAppSdkStablePackageVersion) + 2.4.1-experimental 6.2.11 1.4.0 2.0.15 diff --git a/tests/WinUIGallery.UnitTests/VersionHelperTests.cs b/tests/WinUIGallery.UnitTests/VersionHelperTests.cs new file mode 100644 index 000000000..cfb4d2f6c --- /dev/null +++ b/tests/WinUIGallery.UnitTests/VersionHelperTests.cs @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Text.RegularExpressions; +using WinUIGallery.Helpers; + +namespace WinUIGallery.UnitTests; + +[TestClass] +public class VersionHelperTests +{ + [TestMethod] + public void VersionDetailsAreAvailable() + { + string sdkDetails = VersionHelper.WinAppSdkDetails; + string runtimeDetails = VersionHelper.WinAppSdkRuntimeDetails; + string runtimePrefix = $"{sdkDetails}, Windows App Runtime "; + + StringAssert.Matches(sdkDetails, new Regex(@"^Windows App SDK \d+\.\d+$")); + StringAssert.StartsWith(runtimeDetails, runtimePrefix); + Assert.IsTrue(Version.TryParse(runtimeDetails[runtimePrefix.Length..], out _)); + } +} diff --git a/tests/WinUIGallery.UnitTests/WinUIGallery.UnitTests.csproj b/tests/WinUIGallery.UnitTests/WinUIGallery.UnitTests.csproj index 315f05321..d957d43da 100644 --- a/tests/WinUIGallery.UnitTests/WinUIGallery.UnitTests.csproj +++ b/tests/WinUIGallery.UnitTests/WinUIGallery.UnitTests.csproj @@ -19,6 +19,7 @@ true false true + true From 241735063d2e00847e6522997aa00cc4e0889031 Mon Sep 17 00:00:00 2001 From: Morten Nielsen Date: Fri, 11 Sep 2026 11:29:53 -0700 Subject: [PATCH 3/7] Adds experimental tags to samples (#2230) ## Description Clearly highlights when a sample is using experimental APIs, and adds PagerControl examples. ## How Has This Been Tested? Manual testing ## Screenshots (if appropriate): image image ## Types of changes - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) --- WinUIGallery/Helpers/ControlInfoDataSource.cs | 1 + WinUIGallery/Models/ControlInfoData.cs | 1 + WinUIGallery/Pages/ItemPage.xaml | 11 ++- .../SampleSupport/Data/ControlInfoData.json | 27 ++++++ .../Data/ControlInfoDataSchema.json | 5 + .../PagerControl/PagerControlBasic.txt | 8 ++ .../PagerControl/PagerControlDisplayModes.txt | 19 ++++ .../PagerControl/PagerControlPage.xaml | 95 +++++++++++++++++++ .../PagerControl/PagerControlPage.xaml.cs | 14 +++ .../PagerControl/PagerControlUnbounded.txt | 17 ++++ WinUIGallery/Styles/ItemTemplates.xaml | 14 +++ 11 files changed, 211 insertions(+), 1 deletion(-) create mode 100644 WinUIGallery/Samples/PagerControl/PagerControlBasic.txt create mode 100644 WinUIGallery/Samples/PagerControl/PagerControlDisplayModes.txt create mode 100644 WinUIGallery/Samples/PagerControl/PagerControlPage.xaml create mode 100644 WinUIGallery/Samples/PagerControl/PagerControlPage.xaml.cs create mode 100644 WinUIGallery/Samples/PagerControl/PagerControlUnbounded.txt diff --git a/WinUIGallery/Helpers/ControlInfoDataSource.cs b/WinUIGallery/Helpers/ControlInfoDataSource.cs index fe707b568..41d1f3cd7 100644 --- a/WinUIGallery/Helpers/ControlInfoDataSource.cs +++ b/WinUIGallery/Helpers/ControlInfoDataSource.cs @@ -104,6 +104,7 @@ private async Task GetControlInfoDataAsync() { string badgeString = item switch { + { IsExperimental: true } => "Experimental", { IsNew: true } => "New", { IsUpdated: true } => "Updated", { IsPreview: true } => "Preview", diff --git a/WinUIGallery/Models/ControlInfoData.cs b/WinUIGallery/Models/ControlInfoData.cs index 22927cdf5..5d13a3fef 100644 --- a/WinUIGallery/Models/ControlInfoData.cs +++ b/WinUIGallery/Models/ControlInfoData.cs @@ -41,6 +41,7 @@ public partial class ControlInfoDataItem public bool IsNew { get; set; } public bool IsUpdated { get; set; } public bool IsPreview { get; set; } + public bool IsExperimental { get; set; } public ObservableCollection Docs { get; set; } = []; public bool IncludedInBuild { get; set; } diff --git a/WinUIGallery/Pages/ItemPage.xaml b/WinUIGallery/Pages/ItemPage.xaml index 9b1aaee5a..3252b1848 100644 --- a/WinUIGallery/Pages/ItemPage.xaml +++ b/WinUIGallery/Pages/ItemPage.xaml @@ -31,18 +31,27 @@ + + diff --git a/WinUIGallery/SampleSupport/Data/ControlInfoData.json b/WinUIGallery/SampleSupport/Data/ControlInfoData.json index 681e0569f..06ba53609 100644 --- a/WinUIGallery/SampleSupport/Data/ControlInfoData.json +++ b/WinUIGallery/SampleSupport/Data/ControlInfoData.json @@ -2284,6 +2284,33 @@ "ItemsRepeater" ] }, + { + "UniqueId": "PagerControl", + "Tags": [ + "pagination", + "pages", + "navigation" + ], + "Title": "PagerControl", + "BaseClasses": [ + "Object", + "DependencyObject", + "UIElement", + "FrameworkElement", + "Control" + ], + "ApiNamespace": "Microsoft.UI.Xaml.Controls", + "Subtitle": "A control that lets users navigate through a numbered collection of pages.", + "ImagePath": "ms-appx:///Assets/ControlImages/Placeholder.png", + "Description": "PagerControl provides numbered page navigation with multiple display modes and configurable navigation buttons.", + "SourcePath": "/PagerControl", + "IsExperimental": true, + "RelatedControls": [ + "PipsPager", + "ItemsRepeater", + "ListView" + ] + }, { "UniqueId": "ScrollView", "Tags": [ diff --git a/WinUIGallery/SampleSupport/Data/ControlInfoDataSchema.json b/WinUIGallery/SampleSupport/Data/ControlInfoDataSchema.json index e033b88cb..8651990f7 100644 --- a/WinUIGallery/SampleSupport/Data/ControlInfoDataSchema.json +++ b/WinUIGallery/SampleSupport/Data/ControlInfoDataSchema.json @@ -66,6 +66,11 @@ "default": true, "description": "Whether the example page of this control has been updated lately. If true, it will be displayed in the Recently Updated Sample section on the main page and will have a dot on the overview card of this control" }, + "IsExperimental": { + "type": "boolean", + "default": false, + "description": "Whether this sample requires the experimental Windows App SDK. Experimental samples are only included in experimental builds and display experimental banners." + }, "Docs": { "type": "array", "items": { diff --git a/WinUIGallery/Samples/PagerControl/PagerControlBasic.txt b/WinUIGallery/Samples/PagerControl/PagerControlBasic.txt new file mode 100644 index 000000000..4143240bc --- /dev/null +++ b/WinUIGallery/Samples/PagerControl/PagerControlBasic.txt @@ -0,0 +1,8 @@ +--- header +A basic pager +--- xaml + diff --git a/WinUIGallery/Samples/PagerControl/PagerControlDisplayModes.txt b/WinUIGallery/Samples/PagerControl/PagerControlDisplayModes.txt new file mode 100644 index 000000000..24a421c96 --- /dev/null +++ b/WinUIGallery/Samples/PagerControl/PagerControlDisplayModes.txt @@ -0,0 +1,19 @@ +--- header +Pager display modes +--- xaml + + + + diff --git a/WinUIGallery/Samples/PagerControl/PagerControlPage.xaml b/WinUIGallery/Samples/PagerControl/PagerControlPage.xaml new file mode 100644 index 000000000..3d8529c87 --- /dev/null +++ b/WinUIGallery/Samples/PagerControl/PagerControlPage.xaml @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/WinUIGallery/Samples/PagerControl/PagerControlPage.xaml.cs b/WinUIGallery/Samples/PagerControl/PagerControlPage.xaml.cs new file mode 100644 index 000000000..7b763500a --- /dev/null +++ b/WinUIGallery/Samples/PagerControl/PagerControlPage.xaml.cs @@ -0,0 +1,14 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Microsoft.UI.Xaml.Controls; + +namespace WinUIGallery.ControlPages; + +public sealed partial class PagerControlPage : Page +{ + public PagerControlPage() + { + InitializeComponent(); + } +} diff --git a/WinUIGallery/Samples/PagerControl/PagerControlUnbounded.txt b/WinUIGallery/Samples/PagerControl/PagerControlUnbounded.txt new file mode 100644 index 000000000..79344b86f --- /dev/null +++ b/WinUIGallery/Samples/PagerControl/PagerControlUnbounded.txt @@ -0,0 +1,17 @@ +--- header +Unbounded pagers +--- xaml + + + + diff --git a/WinUIGallery/Styles/ItemTemplates.xaml b/WinUIGallery/Styles/ItemTemplates.xaml index cd30fa94b..8d3a0dbcf 100644 --- a/WinUIGallery/Styles/ItemTemplates.xaml +++ b/WinUIGallery/Styles/ItemTemplates.xaml @@ -60,6 +60,20 @@ + + + From f5f7b56680c734d540d62025ce4f7c6866d3d3e9 Mon Sep 17 00:00:00 2001 From: Jesse Collins Date: Fri, 11 Sep 2026 11:43:50 -0700 Subject: [PATCH 4/7] Isolate experimental window sizing in a dedicated sample Restore existing window samples to stable APIs, add a Windowing page using shared experimental tags, and display the SDK channel on Home and Settings. Keep the unrelated test-host resource fix out of this commit. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- README.md | 4 + WinUIGallery/Helpers/VersionHelper.cs | 3 +- WinUIGallery/Helpers/WindowHelper.cs | 28 +++++ .../SampleSupport/Data/ControlInfoData.json | 34 ++++++ .../TabViewWindowingSamplePage.xaml.cs | 4 +- ...pleWindowsCreateSingleThreadedMultiple.txt | 4 +- .../CreateMultipleWindowsPage.xaml.cs | 5 +- .../SampleCode/Window/CreateWindowSample1.txt | 4 +- .../Samples/Windowing/WindowClientSize.txt | 47 ++++++++ .../Windowing/WindowMinimumClientSize.txt | 49 ++++++++ .../Samples/Windowing/WindowingPage.xaml | 108 ++++++++++++++++++ .../Samples/Windowing/WindowingPage.xaml.cs | 77 +++++++++++++ .../VersionHelperTests.cs | 10 +- 13 files changed, 363 insertions(+), 14 deletions(-) create mode 100644 WinUIGallery/Samples/Windowing/WindowClientSize.txt create mode 100644 WinUIGallery/Samples/Windowing/WindowMinimumClientSize.txt create mode 100644 WinUIGallery/Samples/Windowing/WindowingPage.xaml create mode 100644 WinUIGallery/Samples/Windowing/WindowingPage.xaml.cs diff --git a/README.md b/README.md index fabf855d0..be6724199 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,10 @@ Use the normal `Debug` or `Release` configuration; the SDK version is pinned in instead of referencing a shared Windows App SDK framework package. Experimental APIs can change or be removed before a stable release. +The **Windowing APIs** page demonstrates the experimental window sizing properties +and uses the shared experimental badges and warning banner. Existing windowing +samples continue to use stable APIs. + > [!WARNING] > Try deleting [`nuget.config`](nuget.config) and building again if you get the following build error: > > Assets file 'C:\Users\\...\source\repos\WinUI-Gallery\WinUIGallery\obj\WinUIGallery\project.assets.json' not found. Run a NuGet package restore to generate this file. diff --git a/WinUIGallery/Helpers/VersionHelper.cs b/WinUIGallery/Helpers/VersionHelper.cs index bbdcf4007..d563a5896 100644 --- a/WinUIGallery/Helpers/VersionHelper.cs +++ b/WinUIGallery/Helpers/VersionHelper.cs @@ -9,7 +9,8 @@ internal static partial class VersionHelper { // Use SDK-generated version info; self-contained apps don't deploy the framework's Insights resource DLL. public static string WinAppSdkDetails => - $"Windows App SDK {Release.Major}.{Release.Minor}"; + $"Windows App SDK {Release.Major}.{Release.Minor}" + + (string.IsNullOrEmpty(Release.Channel) ? string.Empty : $" ({Release.Channel})"); public static string WinAppSdkRuntimeDetails => WinAppSdkDetails + $", Windows App Runtime {Microsoft.WindowsAppSDK.Runtime.Version.DotQuadString}"; diff --git a/WinUIGallery/Helpers/WindowHelper.cs b/WinUIGallery/Helpers/WindowHelper.cs index 8fc9035d3..35c819f34 100644 --- a/WinUIGallery/Helpers/WindowHelper.cs +++ b/WinUIGallery/Helpers/WindowHelper.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using Microsoft.UI.Windowing; using Microsoft.UI.Xaml; using System; using System.Collections.Generic; @@ -62,6 +63,33 @@ static public double GetRasterizationScaleForElement(UIElement element) return 0.0; } + static public void SetWindowMinSize(Window window, double width, double height) + { + if (window.Content is not FrameworkElement windowContent) + { + System.Diagnostics.Debug.WriteLine("Window content is not a FrameworkElement."); + return; + } + + if (windowContent.XamlRoot is null) + { + System.Diagnostics.Debug.WriteLine("Window content's XamlRoot is null."); + return; + } + + if (window.AppWindow.Presenter is not OverlappedPresenter presenter) + { + System.Diagnostics.Debug.WriteLine("Window's AppWindow.Presenter is not an OverlappedPresenter."); + return; + } + + var scale = windowContent.XamlRoot.RasterizationScale; + var minWidth = width * scale; + var minHeight = height * scale; + presenter.PreferredMinimumWidth = (int)minWidth; + presenter.PreferredMinimumHeight = (int)minHeight; + } + static public List ActiveWindows { get { return _activeWindows; } } static private List _activeWindows = new List(); diff --git a/WinUIGallery/SampleSupport/Data/ControlInfoData.json b/WinUIGallery/SampleSupport/Data/ControlInfoData.json index 06ba53609..721835493 100644 --- a/WinUIGallery/SampleSupport/Data/ControlInfoData.json +++ b/WinUIGallery/SampleSupport/Data/ControlInfoData.json @@ -4062,6 +4062,40 @@ "Title": "Windowing", "IconGlyph": "", "Items": [ + { + "UniqueId": "Windowing", + "Tags": [ + "experimental", + "window sizing", + "client area", + "DIPs", + "Width", + "Height", + "MinWidth", + "MinHeight" + ], + "Title": "Windowing APIs", + "ApiNamespace": "Microsoft.UI.Xaml", + "Subtitle": "Explore experimental Window client-area sizing and minimum-size APIs.", + "ImagePath": "ms-appx:///Assets/ControlImages/AppWindow.png", + "Description": "Set a window's initial client size and minimum dimensions with Window.Width, Height, MinWidth, and MinHeight.", + "IsExperimental": true, + "IsNew": true, + "Docs": [ + { + "Title": "Windows App SDK release channels", + "Uri": "https://learn.microsoft.com/windows/apps/windows-app-sdk/release-channels" + }, + { + "Title": "Window - API", + "Uri": "https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.window?view=windows-app-sdk-2.0-experimental" + } + ], + "RelatedControls": [ + "AppWindow", + "CreateMultipleWindows" + ] + }, { "UniqueId": "AppWindow", "Tags": [ diff --git a/WinUIGallery/SampleSupport/SamplePages/TabViewWindowingSamplePage.xaml.cs b/WinUIGallery/SampleSupport/SamplePages/TabViewWindowingSamplePage.xaml.cs index 936f55f50..697d5f88c 100644 --- a/WinUIGallery/SampleSupport/SamplePages/TabViewWindowingSamplePage.xaml.cs +++ b/WinUIGallery/SampleSupport/SamplePages/TabViewWindowingSamplePage.xaml.cs @@ -31,8 +31,8 @@ private void TabViewWindowingSamplePage_Loaded(object sender, RoutedEventArgs e) currentWindow.SetTitleBar(CustomDragRegion); CustomDragRegion.MinWidth = 188; - currentWindow.MinWidth = 500; - currentWindow.MinHeight = 300; + // Set minimum window size using OverlappedPresenter (requires XamlRoot, so must be done after Loaded). + WindowHelper.SetWindowMinSize(currentWindow, 500, 300); } public void LoadDemoData() diff --git a/WinUIGallery/Samples/CreateMultipleWindows/CreateMultipleWindowsCreateSingleThreadedMultiple.txt b/WinUIGallery/Samples/CreateMultipleWindows/CreateMultipleWindowsCreateSingleThreadedMultiple.txt index c47e8a5e0..74d2807e6 100644 --- a/WinUIGallery/Samples/CreateMultipleWindows/CreateMultipleWindowsCreateSingleThreadedMultiple.txt +++ b/WinUIGallery/Samples/CreateMultipleWindows/CreateMultipleWindowsCreateSingleThreadedMultiple.txt @@ -4,9 +4,6 @@ Create single threaded Multiple Top level Windows(MTW). // Ensure you close the child window before closing the parent window to avoid application crash. var childWindow = new Window() { - // Size the client area in device-independent pixels. - Width = 500, - Height = 500, ExtendsContentIntoTitleBar = true, SystemBackdrop = new MicaBackdrop(), Content = new Page() @@ -22,4 +19,5 @@ var childWindow = new Window() } }; +childWindow.AppWindow.ResizeClient(new SizeInt32(500, 500)); childWindow.Activate(); \ No newline at end of file diff --git a/WinUIGallery/Samples/CreateMultipleWindows/CreateMultipleWindowsPage.xaml.cs b/WinUIGallery/Samples/CreateMultipleWindows/CreateMultipleWindowsPage.xaml.cs index 06b940a61..1db65fd08 100644 --- a/WinUIGallery/Samples/CreateMultipleWindows/CreateMultipleWindowsPage.xaml.cs +++ b/WinUIGallery/Samples/CreateMultipleWindows/CreateMultipleWindowsPage.xaml.cs @@ -4,6 +4,7 @@ using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Media; +using Windows.Graphics; using WinUIGallery.Helpers; namespace WinUIGallery.ControlPages; @@ -19,9 +20,6 @@ private void CreateNewWindow_Click(object sender, RoutedEventArgs e) { var childWindow = new Window() { - // Size the client area in device-independent pixels. - Width = 500, - Height = 500, ExtendsContentIntoTitleBar = true, SystemBackdrop = new MicaBackdrop(), Content = new Page() @@ -41,6 +39,7 @@ private void CreateNewWindow_Click(object sender, RoutedEventArgs e) // otherwise it will crash the app. // This is also used to change the theme for all windows when the app theme changes. WindowHelper.TrackWindow(childWindow); + childWindow.AppWindow.ResizeClient(new SizeInt32(500, 500)); childWindow.Activate(); } } diff --git a/WinUIGallery/Samples/SampleCode/Window/CreateWindowSample1.txt b/WinUIGallery/Samples/SampleCode/Window/CreateWindowSample1.txt index 91eba761e..648cc1b73 100644 --- a/WinUIGallery/Samples/SampleCode/Window/CreateWindowSample1.txt +++ b/WinUIGallery/Samples/SampleCode/Window/CreateWindowSample1.txt @@ -1,9 +1,6 @@ // Ensure you close the child window before closing the parent window to avoid application crash. var childWindow = new Window() { - // Size the client area in device-independent pixels. - Width = 500, - Height = 500, ExtendsContentIntoTitleBar = true, SystemBackdrop = new MicaBackdrop(), Content = new Page() @@ -19,4 +16,5 @@ var childWindow = new Window() } }; +childWindow.AppWindow.ResizeClient(new SizeInt32(500, 500)); childWindow.Activate(); \ No newline at end of file diff --git a/WinUIGallery/Samples/Windowing/WindowClientSize.txt b/WinUIGallery/Samples/Windowing/WindowClientSize.txt new file mode 100644 index 000000000..dc7a1fd59 --- /dev/null +++ b/WinUIGallery/Samples/Windowing/WindowClientSize.txt @@ -0,0 +1,47 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +--- header +Set the initial client size with Window.Width and Window.Height +--- c# +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Media; +using WinUIGallery.Helpers; + +// Requires an experimental Windows App SDK. These APIs can change or be removed. +// Place these methods in a Page. The literals below follow the selected options. +private void OpenSizedWindow_Click(object sender, RoutedEventArgs e) +{ + int width = $(Width); + int height = $(Height); + + Window window = CreateSampleWindow( + "Window.Width / Height (experimental)", + $"Initial client area: {width} by {height} DIPs. You can resize this window. Close it with Alt+F4 or the title bar Close button."); + window.Width = width; + window.Height = height; + + // Activate applies the pending Window size before the first show. + window.Activate(); +} + +private Window CreateSampleWindow(string title, string message) +{ + // The Gallery helper tracks each window and removes it when it closes. + // Gallery shutdown also closes any remaining tracked child windows. + Window window = WindowHelper.CreateWindow(); + window.Title = title; + window.SystemBackdrop = new MicaBackdrop(); + window.Content = new Page + { + RequestedTheme = ThemeHelper.RootTheme, + Content = new TextBlock + { + Margin = new Thickness(24), + Text = message, + TextWrapping = TextWrapping.Wrap + } + }; + return window; +} diff --git a/WinUIGallery/Samples/Windowing/WindowMinimumClientSize.txt b/WinUIGallery/Samples/Windowing/WindowMinimumClientSize.txt new file mode 100644 index 000000000..43589d329 --- /dev/null +++ b/WinUIGallery/Samples/Windowing/WindowMinimumClientSize.txt @@ -0,0 +1,49 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +--- header +Constrain the client size with Window.MinWidth and Window.MinHeight +--- c# +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Media; +using WinUIGallery.Helpers; + +// Requires an experimental Windows App SDK. These APIs can change or be removed. +// Place these methods in a Page. The literals below follow the selected options. +private void OpenMinimumWindow_Click(object sender, RoutedEventArgs e) +{ + int minWidth = $(MinWidth); + int minHeight = $(MinHeight); + + Window window = CreateSampleWindow( + "Window.MinWidth / MinHeight (experimental)", + $"Minimum client area: {minWidth} by {minHeight} DIPs. Try shrinking this window. Close it with Alt+F4 or the title bar Close button."); + window.MinWidth = minWidth; + window.MinHeight = minHeight; + window.Width = 640; + window.Height = 480; + + // Activate applies the pending Window size before the first show. + window.Activate(); +} + +private Window CreateSampleWindow(string title, string message) +{ + // The Gallery helper tracks each window and removes it when it closes. + // Gallery shutdown also closes any remaining tracked child windows. + Window window = WindowHelper.CreateWindow(); + window.Title = title; + window.SystemBackdrop = new MicaBackdrop(); + window.Content = new Page + { + RequestedTheme = ThemeHelper.RootTheme, + Content = new TextBlock + { + Margin = new Thickness(24), + Text = message, + TextWrapping = TextWrapping.Wrap + } + }; + return window; +} diff --git a/WinUIGallery/Samples/Windowing/WindowingPage.xaml b/WinUIGallery/Samples/Windowing/WindowingPage.xaml new file mode 100644 index 000000000..cb07a0220 --- /dev/null +++ b/WinUIGallery/Samples/Windowing/WindowingPage.xaml @@ -0,0 +1,108 @@ + + + + + + + + + - - - diff --git a/WinUIGallery/Samples/CreateMultipleWindows/CreateMultipleWindowsPage.xaml.cs b/WinUIGallery/Samples/CreateMultipleWindows/CreateMultipleWindowsPage.xaml.cs deleted file mode 100644 index 1db65fd08..000000000 --- a/WinUIGallery/Samples/CreateMultipleWindows/CreateMultipleWindowsPage.xaml.cs +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using Microsoft.UI.Xaml; -using Microsoft.UI.Xaml.Controls; -using Microsoft.UI.Xaml.Media; -using Windows.Graphics; -using WinUIGallery.Helpers; - -namespace WinUIGallery.ControlPages; - -public sealed partial class CreateMultipleWindowsPage : Page -{ - public CreateMultipleWindowsPage() - { - this.InitializeComponent(); - } - - private void CreateNewWindow_Click(object sender, RoutedEventArgs e) - { - var childWindow = new Window() - { - ExtendsContentIntoTitleBar = true, - SystemBackdrop = new MicaBackdrop(), - Content = new Page() - { - Content = new TextBlock() - { - Text = "New child window!", - HorizontalAlignment = HorizontalAlignment.Center, - VerticalAlignment = VerticalAlignment.Center, - }, - // Get the theme from the parent. - RequestedTheme = this.ActualTheme, - } - }; - - // We need to track the new window so it can be closed when the app is closing, - // otherwise it will crash the app. - // This is also used to change the theme for all windows when the app theme changes. - WindowHelper.TrackWindow(childWindow); - childWindow.AppWindow.ResizeClient(new SizeInt32(500, 500)); - childWindow.Activate(); - } -} diff --git a/WinUIGallery/Samples/CreateMultipleWindows/CreateMultipleWindowsCreateSingleThreadedMultiple.txt b/WinUIGallery/Samples/Windowing/CreateMultipleWindows.txt similarity index 76% rename from WinUIGallery/Samples/CreateMultipleWindows/CreateMultipleWindowsCreateSingleThreadedMultiple.txt rename to WinUIGallery/Samples/Windowing/CreateMultipleWindows.txt index 74d2807e6..a8122baa1 100644 --- a/WinUIGallery/Samples/CreateMultipleWindows/CreateMultipleWindowsCreateSingleThreadedMultiple.txt +++ b/WinUIGallery/Samples/Windowing/CreateMultipleWindows.txt @@ -1,14 +1,14 @@ --- header -Create single threaded Multiple Top level Windows(MTW). +Create a single-threaded top-level Window. --- c# // Ensure you close the child window before closing the parent window to avoid application crash. -var childWindow = new Window() +Window childWindow = new Window { ExtendsContentIntoTitleBar = true, SystemBackdrop = new MicaBackdrop(), - Content = new Page() + Content = new Page { - Content = new TextBlock() + Content = new TextBlock { Text = "New child window!", HorizontalAlignment = HorizontalAlignment.Center, @@ -19,5 +19,6 @@ var childWindow = new Window() } }; +WindowHelper.TrackWindow(childWindow); childWindow.AppWindow.ResizeClient(new SizeInt32(500, 500)); childWindow.Activate(); \ No newline at end of file diff --git a/WinUIGallery/Samples/Windowing/WindowingPage.xaml b/WinUIGallery/Samples/Windowing/WindowingPage.xaml index cb07a0220..186fc2bbc 100644 --- a/WinUIGallery/Samples/Windowing/WindowingPage.xaml +++ b/WinUIGallery/Samples/Windowing/WindowingPage.xaml @@ -10,10 +10,23 @@ - + +