Skip to content
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

MetroWindow: Application Crash on Double-Clicking Upper Left Icon #4445

Closed
Fishayyy opened this issue Dec 6, 2023 · 8 comments · Fixed by #4446
Closed

MetroWindow: Application Crash on Double-Clicking Upper Left Icon #4445

Fishayyy opened this issue Dec 6, 2023 · 8 comments · Fixed by #4446
Labels
Milestone

Comments

@Fishayyy
Copy link

Fishayyy commented Dec 6, 2023

Description

Issue: Double-clicking the icon in the upper left corner of a MetroWindow causes the application to crash. This behavior is observed even in the MahApps demo application.

Expected Behavior: Double-clicking the icon typically opens then closes the system menu, or should do nothing if 'ShowSystemMenu' is set to 'False'.

Actual Behavior: The application crashes upon double-clicking the upper left window icon.

Steps to Reproduce

  1. Open any application that utilizes MetroWindow from MahApps.
  2. Double-click on the icon located in the upper left corner of the window.
  3. Observe that the application crashes.

This issue is also reproducible in the official MahApps demo application.

Environment

  • MahApps Version: v2.4.10
  • .NET Version: .NET 8.0
  • Operating System: Windows 11
  • Visual Studio Version: Visual Studio 2022
  • Build Configuration: Debug and Release

Additional Context

  • The issue persists across different MahApps themes and configurations.
  • No relevant exceptions or error messages are observed but I have not setup any special logging to monitor this.
@Fishayyy Fishayyy added the Bug label Dec 6, 2023
@punker76
Copy link
Member

punker76 commented Dec 7, 2023

@Fishayyy Hi, do you have an exception or something else which we can investigate?

@Fishayyy
Copy link
Author

Fishayyy commented Dec 7, 2023

@Fishayyy Hi, do you have an exception or something else which we can investigate?

Unfortunately I have tried changing my debug settings to catch all unhandled exceptions and it appears that none are being thrown which makes me think that the application is actually closing instead of crashing. I also don't see anything in the Windows Event Viewer. I'm going to try and look through some of the code related to the MetroWindow Icon to see if I can find anything useful.

@Fishayyy
Copy link
Author

Fishayyy commented Dec 7, 2023

@Fishayyy Hi, do you have an exception or something else which we can investigate?

I found the code responsible for the behavior here:

private void IconMouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left)
{
if (e.ClickCount == 2)
{
this.Close();
}
else if (this.ShowSystemMenu)
{
#pragma warning disable 618
ControlzEx.SystemCommands.ShowSystemMenuPhysicalCoordinates(this, this.PointToScreen(new Point(this.BorderThickness.Left, this.TitleBarHeight + this.BorderThickness.Top)));
#pragma warning restore 618
}
}
}

Given that this is a private event for the MetroWindow is there a way I can prevent this behavior?

@punker76
Copy link
Member

punker76 commented Dec 8, 2023

@Fishayyy This close behavior is the same as for other windows programs, just tested it with the explorer and it does exactly the same.

@punker76
Copy link
Member

punker76 commented Dec 8, 2023

@Fishayyy The only difference is that if the menu is already open it will close on another single click on the icoon.

@timunie
Copy link
Collaborator

timunie commented Dec 8, 2023

@punker76 interesting enough, it is not the default behavior for all programs. In win10 it does close explorer for me, in Win11 not. Some other programs do close, others not. So maybe this should be configurable somehow 🤔

  • make the void virtual to be able to override it?
  • Add a property for it CloseOnIconDoubleClick {get; set;} = true

@Fishayyy
Copy link
Author

Fishayyy commented Dec 8, 2023

@punker76 wow, all these years and I never even noticed that. I'll have to try that out tomorrow as a sanity check. It would still be nice if I can find a way to prevent that, but that's an interesting realization! I suppose this bug report can be closed out if it's not really a bug. Thank you for the insight!

@Fishayyy
Copy link
Author

Fishayyy commented Dec 8, 2023

@punker76 interesting enough, it is not the default behavior for all programs. In win10 it does close explorer for me, in Win11 not. Some other programs do close, others not. So maybe this should be configurable somehow 🤔

  • make the void virtual to be able to override it?
  • Add a property for it CloseOnIconDoubleClick {get; set;} = true

I like this idea! I've been playing around with different apps today and it defiantly seems like the default Windows behavior is to open system menu on click and close the window on double click for all my Microsoft Office apps and a few other various apps, but then there are things like Visual Studio Code and the Calculator app that treat the icon as a part of the title bar.

@punker76 punker76 added this to the 3.0.0 milestone Dec 10, 2023
punker76 added a commit that referenced this issue Dec 10, 2023
Add new property CloseOnIconDoubleClick to allow disable closing window if the user double clicks on window icon.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

3 participants