views:

1562

answers:

3

How to get the minimize box click event of a WPF window?

A: 

Sorry this is not about WPF as I have not worked much with WPF. But one more thing you can do is check for Windowstate property during Resized event of Form. And if it is equal to FormWindowState.Minimized then minimize button is clicked (?) ;-)

Shoban
+9  A: 

There's an event called StateChanged which (from the help) looks like it might do what you want.

Occurs when the window's WindowState property changes.

The help says it's only supported in .NET 3.0 and 3.5 under Vista, but I've just tried it on XP and it fires when the window is minimized, maximized and restored. However, from my testing, it looks like it fires after the state has changed, so if you want to do something before the window minimized this might not be the approach you need.

You'll have to check the actual state to make sure it's correct.

    private void Window_StateChanged(object sender, EventArgs e)
    {
        switch (this.WindowState)
        {
            case WindowState.Maximized:
                MessageBox.Show("Maximized");
                break;
            case WindowState.Minimized:
                MessageBox.Show("Minimized");
                break;
            case WindowState.Normal:
                MessageBox.Show("Normal");
                break;
        }
    }

Obviously if I was just printing out the state I'd use this.WindowState.ToString() ;)

The following should get added to the XAML defintion of your window by Visual Studio:

StateChanged="Window_StateChanged"
ChrisF
+1  A: 

In addition to Shoban's answer...

You can make use of Window's Deactivated event, you can even use StateChange Event as below

private void Window_Deactivated(object sender, EventArgs e)
{
      if(this.WindowState== WindowState.Minimized)
           // Do your stuff

}

it would help....

Prashant