MaterialDesignInXAML / MaterialDesignInXAML/MaterialDesignInXamlToolkit
Window becomes inactive after DialogHost.Show()
@MichelMichels is already working on this.
Since Mar 31, 2024.
- Dominant language
- C#
- Stars
- 16.3k
- Forks
- 3.5k
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 8
Description
### 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.