How to get the minimize box click event of a WPF window?
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 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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With