I have three windows. FirstWindow
, SecondWindow
and ThirdWindow
. FirstWindow
has button and click on this button opens the SecondWindow
. Analogously, SecondWindow
has button and click on this button opens the ThirdWindow
. Owner
property of the SecondWindow
is set as FirstWindow
and Owner
property of the ThirdWindow
is set as SecondWindow
. The scenario discribing problem:
Open all windows in a row. It will be looked like this:
Then minimize all windows by click on corresponding icon at top right corner of ThirdWindow
.
If you will try to maximize all windows by clicking on FirstLevelWindow
or ThirdLevelWinow
in taskbar - all will be ok, three windows will be maximized. But if you will click on SecondWindow
you will see this:
How can I fix it, or it is just WPF
bug? I can give archived expample project if it helps.
UPDATE
Minimize window - click "_" icon, left icon in iconbar of the window. All windows are modal, i.e it opens with ShowDialog()
method, not with Show()
method. So if you minimize third window - all the windows will be minimized.
Here the code if you don't want download project by link:
FirstWindow
XAML:
<Button Click="OpenChildWindow"
Content="ChildWindow"/>
FirstWindow
.cs:
private void OpenChildWindow(Object sender, RoutedEventArgs e)
{
var window = new SecondLevelWindow();
window.Owner = this;
window.ShowDialog();
}
SecondWindow
XAML:
<Button Click="OpenChildWindow"
Content="ChildWindow"/>
SecondWindow
.cs:
private void OpenChildWindow(Object sender, RoutedEventArgs e)
{
var window = new ThirdLevelWindow();
window.Owner = this;
window.ShowDialog();
}
ThirdWindow
is empty window without any content.
Here link to example project
I've just found, that bug is not reproduced if property ResizeMode
of ThirdWindow
is set to "NoResize". Mb it will be usefull information.
Well, I admit I have no idea what is going on. Did you try to add a fourth window? This become even stranger: the second window bring back the third, but the fourth is still not back.
Anyway, If I had to manage this problem, I would keep a reference of my childWindow in each parent Window. This way on any interesting event (like activate on the second window in your example) I could manage the state of my child as required (WindowState.Normal
in your case).
It could be something like that: in xaml of secondWindow:
Activated="SecondLevelWindow_OnActivated"
And then in code behind:
private ThirdLevelWindow _window;
public SecondLevelWindow()
{
InitializeComponent();
}
private void OpenChildWindow(Object sender, RoutedEventArgs e)
{
_window = new ThirdLevelWindow ();
_window.Owner = this;
_window.ShowDialog();
}
public void SecondLevelWindow_OnActivated(object sender, EventArgs e)
{
if (_window != null)
{
_window.WindowState = WindowState.Normal;
}
}
This is a start, but you could also inspect your current state to define the state of your child.
Hope it helps.