Skip to content

Child window exception fix #2007

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
89 changes: 0 additions & 89 deletions WinUIGallery/Helpers/Win32WindowHelper.cs

This file was deleted.

5 changes: 2 additions & 3 deletions WinUIGallery/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ private void SetWindowProperties()
this.SetTitleBar(titleBar);
this.AppWindow.SetIcon("Assets/Tiles/GalleryIcon.ico");
this.AppWindow.TitleBar.PreferredHeightOption = TitleBarHeightOption.Tall;

Win32WindowHelper win32WindowHelper = new Win32WindowHelper(this);
win32WindowHelper.SetWindowMinMaxSize(new Win32WindowHelper.POINT() { x = 640, y = 500 });
(this.AppWindow.Presenter as OverlappedPresenter).PreferredMinimumWidth = 640;
(this.AppWindow.Presenter as OverlappedPresenter).PreferredMinimumHeight = 500;
Comment on lines +64 to +65
Copy link
Preview

Copilot AI Aug 1, 2025

Choose a reason for hiding this comment

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

The cast to OverlappedPresenter could fail if the presenter is not of that type, potentially causing a NullReferenceException. Consider adding a null check or type check before setting the properties.

Suggested change
(this.AppWindow.Presenter as OverlappedPresenter).PreferredMinimumWidth = 640;
(this.AppWindow.Presenter as OverlappedPresenter).PreferredMinimumHeight = 500;
var overlappedPresenter = this.AppWindow.Presenter as OverlappedPresenter;
if (overlappedPresenter != null)
{
overlappedPresenter.PreferredMinimumWidth = 640;
overlappedPresenter.PreferredMinimumHeight = 500;
}

Copilot uses AI. Check for mistakes.

Comment on lines +64 to +65
Copy link
Preview

Copilot AI Aug 1, 2025

Choose a reason for hiding this comment

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

The cast to OverlappedPresenter could fail if the presenter is not of that type, potentially causing a NullReferenceException. Consider adding a null check or type check before setting the properties.

Suggested change
(this.AppWindow.Presenter as OverlappedPresenter).PreferredMinimumWidth = 640;
(this.AppWindow.Presenter as OverlappedPresenter).PreferredMinimumHeight = 500;
var presenter = this.AppWindow.Presenter as OverlappedPresenter;
if (presenter != null)
{
presenter.PreferredMinimumWidth = 640;
presenter.PreferredMinimumHeight = 500;
}

Copilot uses AI. Check for mistakes.

}

private void OnPaneDisplayModeChanged(NavigationView sender, NavigationViewDisplayModeChangedEventArgs args)
Expand Down
Original file line number Diff line number Diff line change
@@ -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 Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media;
Expand All @@ -12,7 +13,6 @@ namespace WinUIGallery.SamplePages;
public sealed partial class TabViewWindowingSamplePage : Page
{
private const string DataIdentifier = "MyTabItem";
private Win32WindowHelper win32WindowHelper;
private Window tabTearOutWindow = null;

public TabViewWindowingSamplePage()
Expand All @@ -24,8 +24,8 @@ public TabViewWindowingSamplePage()

public void SetupWindowMinSize(Window window)
{
win32WindowHelper = new Win32WindowHelper(window);
win32WindowHelper.SetWindowMinMaxSize(new Win32WindowHelper.POINT() { x = 500, y = 300 });
(window.AppWindow.Presenter as OverlappedPresenter).PreferredMinimumWidth = 640;
(window.AppWindow.Presenter as OverlappedPresenter).PreferredMinimumHeight = 500;
Comment on lines +27 to +28
Copy link
Preview

Copilot AI Aug 1, 2025

Choose a reason for hiding this comment

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

The cast to OverlappedPresenter could fail if the presenter is not of that type, potentially causing a NullReferenceException. Consider adding a null check or type check before setting the properties.

Suggested change
(window.AppWindow.Presenter as OverlappedPresenter).PreferredMinimumWidth = 640;
(window.AppWindow.Presenter as OverlappedPresenter).PreferredMinimumHeight = 500;
if (window.AppWindow.Presenter is OverlappedPresenter overlappedPresenter)
{
overlappedPresenter.PreferredMinimumWidth = 640;
overlappedPresenter.PreferredMinimumHeight = 500;
}
else
{
// Handle the case where the presenter is not an OverlappedPresenter
System.Diagnostics.Debug.WriteLine("The presenter is not of type OverlappedPresenter.");
}

Copilot uses AI. Check for mistakes.

Comment on lines +27 to +28
Copy link
Preview

Copilot AI Aug 1, 2025

Choose a reason for hiding this comment

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

The cast to OverlappedPresenter could fail if the presenter is not of that type, potentially causing a NullReferenceException. Consider adding a null check or type check before setting the properties.

Suggested change
(window.AppWindow.Presenter as OverlappedPresenter).PreferredMinimumWidth = 640;
(window.AppWindow.Presenter as OverlappedPresenter).PreferredMinimumHeight = 500;
var presenter = window.AppWindow.Presenter as OverlappedPresenter;
if (presenter != null)
{
presenter.PreferredMinimumWidth = 640;
presenter.PreferredMinimumHeight = 500;
}

Copilot uses AI. Check for mistakes.

}

private void TabViewWindowingSamplePage_Loaded(object sender, RoutedEventArgs e)
Expand Down