Skip to content

Replace MainWindow with plain Window in sample projects - #2063

Merged
Marcel W. (marcelwgn) merged 5 commits into
microsoft:mainfrom
AndrewKeepCoding:child-window-fix
Dec 20, 2025
Merged

Marcel W. (marcelwgn) merged 5 commits into
microsoft:mainfrom
AndrewKeepCoding:child-window-fix

Conversation

@AndrewKeepCoding

Copy link
Copy Markdown
Contributor

Description

This PR updates WindowHelper.CreateWindow() to return a plain Window instead of MainWindow, which was tightly coupled to several static members.

Motivation and Context

Fixes #2062.

How Has This Been Tested?

Manually tested.

Screenshots (if appropriate):

image

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
private void createNewWindow_Click(object sender, RoutedEventArgs e)
{
var newWindow = new MainWindow();
var newWindow = new Window

Copy link
Copy Markdown
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
Copy Markdown
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.🙂

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I agree with the both of you, its difficult to read but for the sake of the sample we should not rely on helpers. Do we need to need to have ThemeHelper provide the theme?
Also can we call the constructor instead of omitting the "()"? 😄

@AndrewKeepCoding Andrew KeepCoding (AndrewKeepCoding) Dec 18, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

for the sake of the sample we should not rely on helpers

I completely agree.

Do we need to need to have ThemeHelper provide the theme?

If we want the new window use the app theme, which might differ from the system theme, we should set it here using ThemeHelper. We can remove it from the sample code (CreateWindowSample1.txt).
We can get the theme from the parent.

Also can we call the constructor instead of omitting the "()"? 😄

Yes, we can, but I'll add them back since I'm not sure is preferred or not. 🙂

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I agree with the both of you, its difficult to read but for the sake of the sample we should not rely on helpers. Do we need to need to have ThemeHelper provide the theme?
Also can we call the constructor instead of omitting the "()"? 😄

Comment thread WinUIGallery/Samples/SampleCode/Window/CreateWindowSample1.txt Outdated
@marcelwgn

Copy link
Copy Markdown
Contributor

/azp run

@marcelwgn
Marcel W. (marcelwgn) enabled auto-merge (squash) December 20, 2025 12:39
@marcelwgn
Marcel W. (marcelwgn) merged commit 956aebf into microsoft:main Dec 20, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants