There are two
Window
properties which control the behavior of the activation of the application. If you use them properly, all the windows of the application will behave like one application, so no window of any other application cannot appear in between in Z order.
This behavior will be achieved for all windows, not only the main and the modal ones.
First one is
System.Windows.Window.Owner
:
http://msdn.microsoft.com/en-us/library/system.windows.window.owner.aspx[
^].
To achieve right behavior, you need to leave the main window not owned (naturally), and all other windows should be owned by the main one. More complex ownership relation is quite possible but makes not much sense.
The second one is not so important, it only adds some consistency: you should set the Boolean property
ShowInTaskbar
to true for the main window, false for all others. Please see:
http://msdn.microsoft.com/en-us/library/system.windows.window.showintaskbar.aspx[
^].
Now, let's see at the documentation on
ShowDialog
:
http://msdn.microsoft.com/en-us/library/system.windows.window.showdialog.aspx[
^].
A window that is opened by calling the ShowDialog method does not automatically have a relationship with the window that opened it; specifically, the opened window does not know which window opened it. This relationship can be established using the Owner property and managed using the OwnedWindows property.
So, you need to set the property
Owner
of the modal window as well, to get expected behavior. Please try. I don't understand why this is not done through
ShowDialog
, automatically, but the fact is: WPF application does not provide a default way of knowing the main window (you can develop such code yourself), and the method
ShowDialog
does not have a parameter to indicate ownership.
Please try it. If it does not resolve your problem, it would mean you screw up something somewhere else, but I don't thinks so. Please report back if it helps or not.
—SA