Is it possible for Owner window in WPF be on top of Child window when you click on it while Owner window is below Child window?
here is example how I call child window:
Window2 window = new Window2();
window.Owner = this;
window.Show();
Parent/Owner window will always be under child window.
I ran into a similar situation. I solved this by simply removing the owner after showing the window.
Window2 window = new Window2();
window.Owner = this;
window.Show();
window.Owner = null;
Edit: Someone replied to this, and while looking at it, I decided I wanted to make an extension method.
public static void ShowAsIfChildOf(this Window childWindow, Window parentWindow)
{
childWindow.Owner = parentWindow;
childWindow.Show();
childWindow.Owner = null;
}
Many of the answers on this page involve nulling-out the Window.Owner
property for some or all of the (non-MainWindow
) windows in your System.Windows.Application
. While this is a simple and easy fix that does indeed, in isolation, fix the issue of Window
overlap, unfortunately it also inhibits a lot of useful application-wide functionality that WPF seems otherwise eager to provide in the areas of:
Application
activation/deactivation (via mouse-click, desktop Alt-Tab switching, etc...),Application.ShutdownMode
property, and generally,Application
upon shutdown.It is possible fix the Window
overlap issue while still preserving these system-wide WPF features by instead designating a special invisible window instance as your Application.MainWindow
.
Modify your application so that the first Window
it creates--which is the Window
that gets assigned to Application.MainWindow
--is a special dummy Window
that is then made invisible by setting its Visibility
to Visibility.Hidden
or calling Window.Hide()
. This will not hide its owned windows. Then, ensure that your desired "main" window containing your true content, plus all the other windows, owned by this invisible window.
Once hidden, the dummy Window
will not show in the Windows 10 taskbar. You can set the Window.ShowInTaskbar
property on whichever of the visible windows you deem appropriate to simulate apparent special designation, as required.
This approach allows any of the visible windows in your Application
to be on top of the others, while still preserving WPF features and behaviors for system-wide app activation. For example, when the Application
is activated (by clicking on any one of the windows, or via Alt-tab), all of the application's windows are together brought above any other desktop app windows, while still preserving the most recent "in-app" Z-order. WPF shutdown functionality is also preserved, including correct observation of the Application.ShutdownMode
logic in accordance with the invisible MainWindow
(or all the others) being closed.
To get the behavior you want, you don't want to set the Owner on either window.
You, of course will have to handle the logic yourself when closing either of the windows to close your imaginary "child" window.
There may be some other logic you'll have to implement related to minimizing, maximizing, etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With