1

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:

enter image description here

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:

enter image description here

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.

monstr
  • 1,680
  • 1
  • 25
  • 44
  • What do you mean by "Then minimize all windows by click on corresponding icon at top right corner of ThirdWindow" ? If you do this I expect only the third window to be minimized. Also how do you show them as modal or non-modal ? – Adrian Fâciu Aug 22 '14 at 07:00
  • @Adrian Faciu, see update plz – monstr Aug 22 '14 at 07:09
  • 1
    Cannot reproduce this problem on Windows 8, if I minimize the 3rd window none of the other two are affected. – Adrian Fâciu Aug 22 '14 at 08:03
  • @Adrian Faciu, what does it mean "none of the other two are affected"? Only third window minimized? O_o. I can give the sample project if you interested. – monstr Aug 22 '14 at 08:54
  • @monstr, I think that *none of the other two are affected* is quite self explanatory. It means that the third `Window` was minimised and the other two were not. – Sheridan Aug 22 '14 at 09:09
  • @Sheridan, it is impossible if you implement my scenario exactly (Owner property must be set properly) - it was cause my wonder – monstr Aug 22 '14 at 09:11
  • Impossible on *your* computer using *your* code perhaps, but not for everyone else with their code (and possibly different operating systems). If you are so sure, then please edit your question to provide a small, working code example that demonstrates your problem. There is no other way for us to test it. Also, external links to code do not go down so well on this website... we don't want to trawl through large projects... just the [bare minimum required to reproduce your problem](http://stackoverflow.com/help/mcve) please. – Sheridan Aug 22 '14 at 09:16
  • I added link to zipped very small working code project. I don't think you want to see code of three window. Btw, If you set owner property properly, then Adrian Faciu's scenario is impossible :) Owner property garantied that Owner window will be minimized together with child window, when child is minimized. – monstr Aug 22 '14 at 09:22
  • @Sheridan, to reproduce my problem you need to create project with three windows. I've already made it for you. Just download and unzip. – monstr Aug 22 '14 at 09:24
  • Someone might do that, but as I just told you, *external links to code do not go down so well on this website*. It is far more common for users to provide the *relevant* code in their question. – Sheridan Aug 22 '14 at 09:36
  • @ Sheridan, I would gladly represent the code if it helps, and I usually give the code in my questions. But, as I already told, to see this bug, to reproduce my trouble, you need to make project with three windows, start project and click-click-click. I.e. repeat the scenario I described. If I place all code here (3 windows with buttons), you just copy-paste it to your project to test, am I right? So why do that if I give you whole working project? I think, if someone really interested – he will download project and test it. – monstr Aug 22 '14 at 09:46
  • I observe the same behaviour than monstr (on Windows 8), by downloading his project. It is important to understand than each window is a child of the previous one, this is why you do no expect only the third window to be reduce – Ouarzy Aug 22 '14 at 13:11

1 Answers1

2

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.

Ouarzy
  • 3,015
  • 1
  • 16
  • 19
  • Yes, I tried add fourth window and observed the the same behaviour. Fourth window is not maximized. Thus, last window in chain of windows is not always maximized. Your approach is working. But I think in MVVM (for example) it is not a good idea to hold links to child window in ViewModel of parent window. – monstr Aug 25 '14 at 05:17
  • Well, as it is a pure UI responsability, I would find acceptable such a solution in my MVVM projects. Still I agree this is not a perfect workaround. – Ouarzy Aug 25 '14 at 07:35