Avalonia ShowDialog and a Minimize Button
If you use ShowDialog in Avalonia, you will notice that under KDE/Wayland, window will retain minimize button. Even worse, minimize will hide the window, leaving its owner visible but not clickable. Slightly annoying and user might not even understand immediatelly why clicks on the main window are not working until they restore minimized dialog.
And, try as I might, I found no way to remove minimize box without removing the whole title. Since I was not in the mood to handle titleless windows, the next best thing was to close dialog window on minimize. Of course, detecting when window gets minimized is not really straightforward.
In the end, this is the code I ended up using:
PropertyChanged += (sender, e) => {
if (e.Property == Window.WindowStateProperty && WindowState == WindowState.Minimized) {
Dispatcher.UIThread.InvokeAsync(() => {
WindowState = WindowState.Normal;
Close();
});
}
};We inject our check into the general PropertyChanged event handling. However, we cannot directly close window here as it will not revert focus to the owner. What we need is to ask dispatcher to invoke our code once UI thread has a spare moment. Then we restore the freshly minimized window, followed by close.
Not great, but not terrible either.