-1

Hi I want to Maximize window in WPF and I use below lines:

private void mnu_maximize_Click(object sender, RoutedEventArgs e)
{
    if (main.WindowState == System.Windows.WindowState.Maximized)
        main.WindowState = System.Windows.WindowState.Normal;
    main.WindowState = System.Windows.WindowState.Maximized;

}

But the problem is when i click again for restore window to normal state it's not working and it's Stuck in Maximized state.
So How Can i fix this?

sujith karivelil
  • 28,671
  • 6
  • 55
  • 88

1 Answers1

6

Add an else part :

if (main.WindowState == System.Windows.WindowState.Maximized)
    main.WindowState = System.Windows.WindowState.Normal;
else
    main.WindowState = System.Windows.WindowState.Maximized;

Updates:

In the given code, the conditional statement(if) is doing nothing, in all case the main.WindowState will be set to Maximized. That's why I told you to introduce an else there.

sujith karivelil
  • 28,671
  • 6
  • 55
  • 88
  • 3
    @komeilshahmoradi : In the given code, the conditional statement(`if`) is doing nothing, in all case the `main.WindowState` will be set to `Maximized`. That's why i told you to introduce a else there. – sujith karivelil Aug 24 '16 at 06:34