MaterialDesignInXAML / MaterialDesignInXAML/MaterialDesignInXamlToolkit

Window becomes inactive after DialogHost.Show()

Abierto
#3,497 12 comentarios 0 reacciones 1 asignado Ver en GitHub

@MichelMichels ya está trabajando en esto.

Desde el 31/3/2024.

bug dialoghost
Lenguaje dominante
C#
Estrellas
16.3k
Forks
3.5k
Merge medio
1 d 22 h
PR fusionados (30 d)
8

Descripción

### 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:**

https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/assets/12599641/870a9dc8-6a78-467a-923e-92513d43876c

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:**

https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/assets/12599641/47933a28-e0f8-4cf1-8cea-f3b8a798802f

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

My code:

**PreloaderDialog**
```csharp

```

**MainWindow**
```csharp


...

```

**Method to show preloader**
```csharp
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**
```csharp
DialogUtils.DoWithPreloader(() => {
// some time-consuming code
});
```

### Version

5.0.1-ci571

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.