diff --git a/WinUIGallery/Helpers/WindowHelper.cs b/WinUIGallery/Helpers/WindowHelper.cs index a3d6c6a07..cb6c3531a 100644 --- a/WinUIGallery/Helpers/WindowHelper.cs +++ b/WinUIGallery/Helpers/WindowHelper.cs @@ -19,7 +19,7 @@ public partial class WindowHelper { static public Window CreateWindow() { - MainWindow newWindow = new MainWindow(); + var newWindow = new Window(); TrackWindow(newWindow); return newWindow; } diff --git a/WinUIGallery/Samples/ControlPages/CreateMultipleWindowsPage.xaml.cs b/WinUIGallery/Samples/ControlPages/CreateMultipleWindowsPage.xaml.cs index 3ad384e77..8659a68a1 100644 --- a/WinUIGallery/Samples/ControlPages/CreateMultipleWindowsPage.xaml.cs +++ b/WinUIGallery/Samples/ControlPages/CreateMultipleWindowsPage.xaml.cs @@ -3,8 +3,9 @@ using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Media; +using Windows.Graphics; using WinUIGallery.Helpers; -using WinUIGallery.Pages; namespace WinUIGallery.ControlPages; @@ -17,12 +18,29 @@ public CreateMultipleWindowsPage() private void createNewWindow_Click(object sender, RoutedEventArgs e) { - var newWindow = new MainWindow(); + var newWindow = new Window + { + ExtendsContentIntoTitleBar = true, + SystemBackdrop = new MicaBackdrop(), + Content = new Page + { + // The TreeHelper is a helper class in the WinUIGallery project + // that allows us to find the current theme of the app. + RequestedTheme = ThemeHelper.RootTheme, + Content = new TextBlock + { + Text = "New Window!", + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Center, + }, + } + }; + + newWindow.AppWindow.ResizeClient(new SizeInt32(500, 500)); + + // The WindowHelper is a helper class in the WinUIGallery project + // that helps us close child windows when the main window closes. WindowHelper.TrackWindow(newWindow); newWindow.Activate(); - - var targetPageType = typeof(HomePage); - string targetPageArguments = string.Empty; - newWindow.Navigate(targetPageType, targetPageArguments); } } diff --git a/WinUIGallery/Samples/SampleCode/Window/CreateWindowSample1.txt b/WinUIGallery/Samples/SampleCode/Window/CreateWindowSample1.txt index 938d39d2f..a4e0f3e63 100644 --- a/WinUIGallery/Samples/SampleCode/Window/CreateWindowSample1.txt +++ b/WinUIGallery/Samples/SampleCode/Window/CreateWindowSample1.txt @@ -1,11 +1,24 @@ -// C# code to create a new window -var newWindow = WindowHelper.CreateWindow(); -var rootPage = new NavigationRootPage(); -rootPage.RequestedTheme = ThemeHelper.RootTheme; -newWindow.Content = rootPage; -newWindow.Activate(); +var childWindow = new Window +{ + ExtendsContentIntoTitleBar = true, + SystemBackdrop = new MicaBackdrop(), + Content = new Page + { + // The TreeHelper is a helper class in the WinUIGallery project + // that allows us to find the current theme of the app. + RequestedTheme = ThemeHelper.RootTheme, + Content = new TextBlock + { + Text = "New Window!", + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Center, + }, + } +}; -// C# code to navigate in the new window -var targetPageType = typeof(HomePage); -string targetPageArguments = string.Empty; -rootPage.Navigate(targetPageType, targetPageArguments); \ No newline at end of file +childWindow.AppWindow.ResizeClient(new SizeInt32(500, 500)); + +// The WindowHelper is a helper class in the WinUIGallery project +// that helps us close child windows when the main window closes. +WindowHelper.TrackWindow(childWindow); +childWindow.Activate(); \ No newline at end of file