Skip to content

Conversation

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

Copy link
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 "()"? 😄

Copy link
Contributor Author

@AndrewKeepCoding AndrewKeepCoding Dec 18, 2025

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
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 "()"? 😄

@marcelwgn
Copy link
Contributor

/azp run

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Child window sample forces parent window navigation

3 participants