WPF:最小化System.Windows.Window的状态

时间:2018-10-23 15:22:02

标签: wpf windows window-position

在最小化之前如何知道System.Windows.Window是处于WindowState.Normal还是WindowState.Maximized?

1 个答案:

答案 0 :(得分:0)

除非您自己跟踪以前的状态,否则您不会这样做:

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;
}

恐怕没有可用的“ PreviousWindowState”属性。