0

WPF 4.5

I've got an app where I show a modal Window from my app's main Window by instantiating it, setting its owner to be the main Window, and then calling ShowDialog(). The modal Window has "Topmost=true". The main Window does not.

When I run my app the modal Window shows in front of the main Window, and it is kept in front of the main Window just as expected. However, I can simply click on the main Window behind the modal Window to Activate the main Window and manipulate it...I can even close it!

In my humble opinion this is definitely not the desired behavior for an application with a modal Window. I'm confused as to why WPF handles it this way. More important, I need a solution that will keep the modal Window in front while also blocking access to the main Window behind it (isn't that supposed to be a basic function of a modal Window?)

I believe this desired behavior has always been the default behavior when using ShowDialog in WinForms (way back in the day.) What am I missing here, and how can I get this working with WPF?

Joey
  • 115
  • 1
  • 15
  • Does this answer your question? [ShowDialog() behind the parent window](https://stackoverflow.com/questions/9855954/showdialog-behind-the-parent-window) – StayOnTarget Jul 30 '21 at 17:42

1 Answers1

0

You have to set the owner window before ShowDialog :

modalWindow.Owner = RootWindow;
Dragos Stoica
  • 1,753
  • 1
  • 21
  • 42
  • 1
    I did that (I stated in the first sentence of my question.) – Joey Mar 25 '15 at 17:04
  • I've discovered this behavior is occurring because of the way I have certain properties set for the Windows. Nevermind!!! (but thanks). – Joey Mar 25 '15 at 17:10
  • Top most interacts with modal state, because it says to the window : "hey, you`re not my root, my root is windows" – Dragos Stoica Mar 25 '15 at 17:40
  • @user2158172 Can you remember, which settings did this strange behaviour? It looks like I have similar problem... – Artholl Nov 09 '16 at 13:22