Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion WinUIGallery/Helpers/WindowHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public partial class WindowHelper
{
static public Window CreateWindow()
{
MainWindow newWindow = new MainWindow();
var newWindow = new Window();
TrackWindow(newWindow);
return newWindow;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -17,12 +18,29 @@ public CreateMultipleWindowsPage()

private void createNewWindow_Click(object sender, RoutedEventArgs e)
{
var newWindow = new MainWindow();
var newWindow = new Window
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading this was painful 😅, can't we just create a NewWindow or SecondaryWindow?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My intension was to avoid adding custom code to the sample as much as possible, but sure I can do that.🙂

{
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);
}
}
33 changes: 23 additions & 10 deletions WinUIGallery/Samples/SampleCode/Window/CreateWindowSample1.txt
Original file line number Diff line number Diff line change
@@ -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);
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();