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

ShowMessageBox freeze primary window when show a message box on secondary windows #374

Open
VShawn opened this issue Jan 17, 2023 · 2 comments

Comments

@VShawn
Copy link

VShawn commented Jan 17, 2023

Description

When call IoC.Get<IWindowManager>().ShowDialog or IoC.Get<IWindowManager>().ShowMessageBox on secondary window, the primary window will be freezen.

With ShowDialog provide by the runtime, primary window works fine.

To Reproduce
Code to reproduce the bug, which someone else can run.

Version Info

  • Stylet version: 1.3.6
  • Runtime version: .Net6

Additional Info

With stylet messagebox:

1

1

With system messagebox:

1

Here is the code related:

https://github.com/1Remote/PRemoteM/blob/dev_net6/Ui/View/Host/TabWindowViewModel.cs#L236-L237

https://github.com/1Remote/PRemoteM/blob/58805bd0bb59757e9016a89cdfd14300a64278b7/Ui/Utils/MessageBoxHelper.cs#L26-L33

And you can get the exe file from:
https://github.com/1Remote/PRemoteM/releases

@VShawn VShawn changed the title ShowDialog freeze primary window when show a message box on secondary windows ShowMessageBox freeze primary window when show a message box on secondary windows Jan 17, 2023
@VShawn
Copy link
Author

VShawn commented Jan 18, 2023

    var window = new InputWindow
    {
        Title = "title",
        Prompt = "Hi, test native owner window",
        Response = "",
        Result = Results.Cancel,
        ShowInTaskbar = false,
    };
    window.Owner = this;
    window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
    window.ShowDialog();

this above will open a modal dialog to freeze both two window.

So using the native func ShowDialog to show a windows will freeze all of the windows.

Then I noted WindowManager.ShowMessageBox based on native ShowDialog.

That's the reason why WindowManager.ShowMessageBox freeze my two windows.

@canton7 can we make WindowManager.ShowMessageBox a same behaviour like native MessageBox.Show ?

@VShawn
Copy link
Author

VShawn commented Jan 18, 2023

I have find a workaround for this ticket. I will make a PR for this latter.

  var mbvm = new MessageBoxViewModel();
  mbvm.Setup("Hi, test stylet message box");
  if (IoC.Get<IViewManager>().CreateAndBindViewForModelIfNecessary(mbvm) is Window window)
  {
      window.Owner = this;
      window.Loaded += (o, args) =>
      {
          var dlgWindow = o as Window;
          // dlg don't have a Owner
          if(dlgWindow?.Owner == null)
              return;
          var windows = Application.Current.Windows;
          // enable the window != Owner
          foreach (Window w in windows)
          {
              if (w == dlgWindow.Owner) continue;
              if (w is { IsLoaded: true })
              {
                  if (HwndSource.FromVisual(w) is HwndSource hwndSource)
                      EnableWindow(hwndSource.Handle, true);
              }
          }
      };
      window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
      window.ShowDialog();
  }

VShawn added a commit to 1Remote/1Remote that referenced this issue Jan 18, 2023
- make a workaround to fix `ShowMessageBox from tab window will freeze primary window`, see canton7/Stylet#374
VShawn added a commit to 1Remote/1Remote that referenced this issue Jan 18, 2023
- make a workaround to fix `ShowMessageBox from tab window will freeze primary window`, see canton7/Stylet#374
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

No branches or pull requests

1 participant