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

DialogManager.ShowDialogExternally() exception if no other window exists #3755

Closed
puchs opened this issue Feb 28, 2020 · 0 comments · Fixed by #3862
Closed

DialogManager.ShowDialogExternally() exception if no other window exists #3755

puchs opened this issue Feb 28, 2020 · 0 comments · Fixed by #3862
Labels
Milestone

Comments

@puchs
Copy link

puchs commented Feb 28, 2020

Describe the bug
Idea: Display a styled MessageBox before the main window is created in case of an unrecoverable error (a RPC server cannot be started). I do not want to create a window just to tell the user the the app is going to shutdown now anyway. I think it is useful to be able to show a dialog without any other window from time to time.

var dialog = new CustomDialog() { Title = "Error" }; dialog = dialog.ShowDialogExternally();

in App.OnStartup should allow me to do just that as it creates a new window, but it will result in a

System.ArgumentException: 'Cannot set Owner property to itself.'

To Reproduce
Steps to reproduce the behavior:

  1. get the repo https://github.com/puchs/MahAppsDialog
  2. build it
  3. run it

Expected behavior
I expect to see a dialog. I do not think another window is actually necessary for this to work. The same is true if a window has been created, but not yet shown. (This results in a different exception, but the reason is the same.)

Environment(please complete the following information):

  • MahApps.Metro version 2.0.0-alpha0660
  • OS: Win10 1909
  • Visual Studio 2019 16.4.5
  • .NET Core 3.1.101

Repo
https://github.com/puchs/MahAppsDialog

Additional context
I think the problem is located in src/MahApps.Metro/Controls/Dialogs/DialogManager.cs, line 597:

private static Window SetupExternalDialogWindow(BaseMetroDialog dialog, [CanBeNull] Window windowOwner = null)
{
var win = CreateExternalWindow();
win.Owner = windowOwner ?? Application.Current?.MainWindow;
...

as this will (as far as I can tell) set the owner of the window in any case. I believe that it should not set the property at all if windowOwner is null.

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.

2 participants