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

Window becomes inactive after DialogHost.Show() #3497

Open
Mishin870 opened this issue Mar 16, 2024 · 4 comments
Open

Window becomes inactive after DialogHost.Show() #3497

Mishin870 opened this issue Mar 16, 2024 · 4 comments
Assignees
Labels
bug dialoghost Waiting on feedback Additional information is needed. Stale items with this label may be closed.

Comments

@Mishin870
Copy link

Bug explanation

I'm trying to make a preloader using DialogHost (I need to display a loading indicator and lock the application while the data is being loaded)

However, when I call DialogHost.Show(), the application window loses focus

5.0.1-ci571:

bandicam.2024-03-16.22-44-17-543.mp4

if you click on a dialog, the window will become active again along with the dialog.
so they are not mutually exclusive

In my past project I used version 4.6.1 and the window did not lose focus when DialogHost was opened

I tried different versions in the current project:

  • 4.10.0-ci317 everything works perfectly
  • 5.0.0-ci321 this bug appears

4.10.0-ci317:

bandicam.2024-03-16.23-30-59-746.mp4

How can this be fixed without downgrading to an older version?

My code:

PreloaderDialog

<UserControl x:Class="Client.View.Dialogs.PreloaderDialog"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             mc:Ignorable="d">
    <ProgressBar Width="24"
                 Height="24"
                 Margin="16"
                 IsIndeterminate="True"
                 Style="{StaticResource MaterialDesignCircularProgressBar}"
                 Value="33" />
</UserControl>

MainWindow

<Window x:Class="Client.View.Windows.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
        xmlns:controls="clr-namespace:Client.View.Controls"
        mc:Ignorable="d"
        Title="FriendSync"
        Height="500" Width="540"
        WindowStartupLocation="CenterScreen">
    <materialDesign:DialogHost
        Identifier="RootDialog"
        DialogTheme="Inherit"
        Loaded="DialogHost_OnInitialized">
        ...
    </materialDesign:DialogHost>
</Window>

Method to show preloader

public static async Task DoWithPreloader(Action action, string host = DIALOG_ROOT) {
  var dialog = new PreloaderDialog();

  if (DialogHost.IsDialogOpen(host)) {
    try {
      DialogHost.Close(host);
    } catch (Exception) {
      // ignored
    }
  }

  await DialogHost.Show(dialog, host, new DialogOpenedEventHandler((_, args) => {
    action();
    try {
      if (!args.Session.IsEnded) {
        args.Session.Close(false);
      }
    } catch (Exception) {
      // ignored
    }
  }));
}

Calling code

DialogUtils.DoWithPreloader(() => {
  // some time-consuming code
});

Version

5.0.1-ci571

@Mishin870 Mishin870 added bug evaluation required Items is pending review or evaluation by the team labels Mar 16, 2024
@MichelMichels MichelMichels self-assigned this Mar 31, 2024
@MichelMichels
Copy link
Member

Can you provide us a test repository which show cases the problem?

@MichelMichels MichelMichels added Waiting on feedback Additional information is needed. Stale items with this label may be closed. dialoghost and removed evaluation required Items is pending review or evaluation by the team labels Apr 1, 2024
@Mishin870
Copy link
Author

Here are the two minimal projects inside the solution
They are identical in everything except the MaterialDesign version

DialogHostTest - v5.0.1-ci588, when clicking on any of the buttons the window title becomes inactive

DowngradedTest - v4.10.0-ci317, the window stays active (which is what I want, it looks nice)

https://github.com/Mishin870/DialogHostTest

@MichelMichels
Copy link
Member

I pinpointed the issue these lines of code in DialogHost.cs.

This change was introduced by @Keboo in this commit. @Keboo do you remember why these lines were necessary?

Copy link
Contributor

github-actions bot commented May 5, 2024

This issue is marked stale because it has been open 30 days with no activity. Remove stale label or update the issue, otherwise it will be closed in 14 days.

@github-actions github-actions bot added the Stale Issues and PRs that have not had activity for a while are marked with this label. label May 5, 2024
@Keboo Keboo removed the Stale Issues and PRs that have not had activity for a while are marked with this label. label May 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug dialoghost Waiting on feedback Additional information is needed. Stale items with this label may be closed.
Projects
None yet
Development

No branches or pull requests

3 participants