MaterialDesignInXAML / MaterialDesignInXamlToolkit

Google's Material Design in XAML & WPF, for C# & VB.Net.
http://materialdesigninxaml.net
MIT License
15.05k stars 3.41k forks source link

Modal is always on top even if application has no focus #2841

Open SDekkers opened 2 years ago

SDekkers commented 2 years ago

Bug explanation

Hi,

My WPF app is set to startup at Windows launch, when it opens it checks if the end user has added their credentials, and if not asks for them in a modal. However, even if the Mainwindow does not have focus, the modal still goes on top of any other open application.

Is this something that can be changed with some (minor) tweaks?

Screenshot below showing modal over File Explorer (which has focus), with main app behind that. image

Version

4.5.0

SDekkers commented 2 years ago

This is probably related to #1612

nicolaihenriksen commented 2 years ago

@SDekkers Could you please provide a bit more context.

I have tried reproducing the issue with the current demo application without any luck. I also tried extending it with delayed openings of the overlay still without luck. I also tried DialogHost.Show() (one of the overloads) since your description seems to indicate this is the way you're using it; still not able to reproduce.

If you could write up a very small sample app showcasing the issue, that would be very helpful. Thanks.

keekis commented 1 year ago

I'm able to reproduce this bug using the standard MaterialDesignDemo app. When visual studio hits the breakpoint shown in attached picture, move another app (like notepad) infront of MaterialDesignDemo app and then click continue in visual studio. Observe that the popup/modal appear on top of the other app/notepad.

dialog-host-issue

Keboo commented 1 year ago

@keekis do you see the problem occur when the debugger is not attached? From your description, it sounds like the TopMost flag on the PopupEx, used by the DialogHost in that example, is not being properly set to false. It toggles this by watching the host window's Activated and Deactivated events. With the debugger attached, and pausing at breakpoints it is possible that the expected events are not getting to the window. Without the debugger attached, I am not able to replicate the behavior. With the debugger attached I can sort of replicate it, but toggling the host window to be activated, then deactivated it the behaves as I would expect.

keekis commented 1 year ago

@Keboo - yes it occurs in a running deployed system and is quite easy to reproduce.

In our system we are running 2 applications - one application- let us call it Map-System is using DialogHost/PopupEx. The 2nd application - Vehicle-System is is used to control the vehicle - this system don't have DialogHost/PopupEx. The driver switches between these system when driving.

When Vehicle-System is activate and the Map-System receives a message, a PopupEx is used to show the message inside the inactive Map-System. The PopupEx will then show on top of the active Vehicle-System.

VarChar42 commented 1 year ago

I have the same issue with a DialogHost inside a Page inside a TabablzControl.

I suspect, that the DialogHost cannot listen for the Activated and Deactivated events inside of the TabablzControl

VarChar42 commented 1 year ago

I reproduced the issue here: https://github.com/VarChar42/MdDialogIssue

But I could not reproduce it without Dragablz so it might not even be an issue of the DialogHost

Keboo commented 1 year ago

@VarChar42 thank you for that repo! I will take a look at it. I was able to reproduce the first case with the break points on my live stream. I suspect there is a combination of issues occurring here.

armandomusto commented 1 year ago

@Keboo any news on this issue?

melsawy93 commented 3 months ago

Has this issue been resolved? Im having a similar issue where I am seeing a dialog pop up even though my mainwindow is minimized. I just see a dialog popping randomly. The dialoghost.open() logic is being triggered by an async function that checks for specific things periodically and shows a dialog.