maybe a bug with Window class when minimizing?

    General discussion

  • I have a dialog in my project, when I minimize it, i want the whole application to minimize so I minimize the owner. This has for effect to remove the dialog from the taskbar. Just try it, you'll be stuck with an app you can't go back to.


    <Window x:Class="minimizeWindow.Window1" 
          <Button Click="OnClick">click</Button> 


    using System; 
    using System.Windows; 
    namespace minimizeWindow 
        public partial class Window1 : Window 
            public Window1() 
            private void OnClick(object sender, RoutedEventArgs e) 
                Window w = new Window(); 
                w.Owner = this
                w.WindowStartupLocation = WindowStartupLocation.CenterScreen; 
                w.ResizeMode = ResizeMode.CanMinimize; 
                w.StateChanged += w_StateChanged; 
                w.Title = "Minimize me"
                w.ShowInTaskbar = true
            private void w_StateChanged(object sender, EventArgs e) 
                WindowState = (sender as Window).WindowState; 



     Also, I'm not sure where I should submit bugs about wpf... is here the place?




    Tuesday, January 27, 2009 4:25 PM

All replies

  • Could you specify, step by step, what you wish to happen and what actually happens?

    I fooled around with your code and everything worked as expected.

    Bigsby, Lisboa, Portugal - O que for, quando for, é que será o que é.
    Tuesday, January 27, 2009 6:14 PM
  •  OK i'll do just that:

    -First there is the 1rst window, it contains a button.

    -Click the button, a Dialog titled "minimize me" opens, with a ShowDialog call and the 1rst window as owner. The 1rst window is locked by the modal dialog.

    -I then minimize the dialog.

    -There is an event handler that will also minimize the first window to clear the screen.

    -The dialog window disappears from the taskbar, that is were the problem is.

    -The original window is still in the taskbar but locked by the dialog that is now impossible to reopen.



    Also i use XP Pro, VS2005 and 3.5 SP1 framework.

    I hope someone will be able to reproduce it because our qa departement does.



    Tuesday, January 27, 2009 6:32 PM
  • Ok. I'm using Vista and that actually doesn't happen.

    - On clicking button on 1st window, dialog opens and a taskbar item is add showing both windows in taskbar.

    - On minimizing dialog, both windows minimize and dialog's taskbar item disappears.

    - On clicking on remaining taskbar icon, both windows open to previous locations and logic, that is, dialog available but blocking owner (1st window).


    I don't have an XP to test this behavior but I am very curious to know the outcome of this thread.
    Bigsby, Lisboa, Portugal - O que for, quando for, é que será o que é.
    Wednesday, January 28, 2009 11:06 AM
  • I just reproduced it on Vista, compiled with VS2005.


    You do the right steps, but when I click on the taskbar icon nothing happens.

    Wednesday, January 28, 2009 3:54 PM
  • Is there an update to this issue?  I'm experiencing the same problem using xaml.

    I have two windows.  Window1 opens Window2 (ShowInTaskbar = false), when you minimize window2 and then click on application in the Taskbar it opens up Window1 even though Window2 is still open and modal.  Window2 should have come back to the top.


    Tuesday, May 19, 2009 4:34 PM
  • Hi,

    Thanks for replying.  We've reproduced this bug and added it to our bug database.

    One workaround is to avoid minimizing the parent of a modal dialog, but it sounds like that is desired.

    Another workaround is to hide the parent when the child is minimized.  The child will remain visible on the taskbar so you can restore it.  Here's the code I used:

            private void w_StateChanged(object sender, EventArgs e)
                if ((sender as Window).WindowState == WindowState.Minimized)

    Tuesday, May 19, 2009 11:23 PM
  • Hey Andre,

    I agree your solution would work if it was only an issue with minimize.  Unfortunately the problem is bigger than that. 

    Take my same example:

    Window1 opens up Window2 as modal (and ShowInTaskbar = false).   Open up another full sized window on top of Window1 and and window2.  Now click on the taskbar, and you'll see that here again Window1 is shown instead of the modal Window2.

    It seems my options are to show all the windows in the taskbar (ick) or to keep a state of the top most window and ensure that it is always visible on focus changes.

    What are your thoughts?  is there another way around this that i'm not thinking of?    It always just worked in Windows Forms so i'm at a bit of a loss.

    One other note:  in Windows Forms you would always pass the parent window into ShowDialog.  Here i can't find a similar notion to truly tie this modal dialog to a parent.  is there such a construct?

    Thanks in advance for your help.

    Wednesday, May 20, 2009 4:15 PM
  • Hey again Andre, I have worked around this bug by listening for the Activated event to fire in my main form. it seems that the main form was always being activated, and this did the trick. Any final thoughts or warnings?
            // mdb - workaround a re-focus bug in Silverlight where if you have a modal dialog
            // and you either minimize of cover it with another window, and then you select your application
            // on the taskbar it will not display the top most modal dialog, it instead displays App.Current.MainWindow.
            // loop through the windows when this form is activated and Activate each one.  if more than one exists, they will
            // be activated in order.
            private bool m_bProcessingActivated = false;
            void WindowMain_Activated(object sender, EventArgs e)
                // process if we're not already processing
                if (!m_bProcessingActivated)
                    // mark us as processing
                    m_bProcessingActivated = true;
                    // ensure no one else got in under the wire
                    if (m_bProcessingActivated)
                        // loop through the windows and activate them
                        foreach (Window oWindow in App.Current.Windows)
                    // free up for others to process
                    m_bProcessingActivated = false;
    • Edited by mdbouchard Wednesday, May 20, 2009 5:23 PM typo
    Wednesday, May 20, 2009 5:20 PM