WPF: State of Minimized System.Windows.Window

96 Views Asked by At

How do I know whether the System.Windows.Window was in WindowState.Normal or WindowState.Maximized before it was minimized?

1

There are 1 best solutions below

1
mm8 On BEST ANSWER

You don't unless you keep track of the previous state yourself:

private WindowState _previousState = WindowState.Normal;
private void MainWindow_StateChanged(object sender, EventArgs e)
{
    if (WindowState == WindowState.Minimized)
    {
        if (_previousState == WindowState.Maximized)
        {
            MessageBox.Show("Window was in maximized state before being minimized");
        }
        else
        {
            MessageBox.Show("Window was in normal state before being minimized");
        }
    }
    _previousState = WindowState;
}

I am afraid there is no "PreviousWindowState" property available.