How to restore a minimized Window in code-behind?

后端 未结 7 901
无人共我
无人共我 2020-12-08 06:24

This is somewhat of a mundane question but it seems to me there is no in-built method for it in WPF. There only seems to be the WindowState property which being

7条回答
  •  天命终不由人
    2020-12-08 06:49

    Here is how i get it to restore right now: I handle the StateChanged event to keep track of the last state that was not Minimized

    WindowState _lastNonMinimizedState = WindowState.Maximized;
    private void Window_StateChanged(object sender, EventArgs e)
    {
        if (this.WindowState != System.Windows.WindowState.Minimized)
        {
            _lastNonMinimizedState = WindowState;
        }
    }
    

    To restore i then have to set that WindowState respectively:

    this.WindowState = _lastNonMinimizedState;
    

提交回复
热议问题