2

I am working on a wpf application and i want to handle windowStateChanged event. I did it like this

if (((Window)sender).WindowState == WindowState.Maximized)
{}
else if (((Window)sender).WindowState == WindowState.Normal)
{}

but whenever i minimize the the window and then maximize it, it come to this(WindowState.Normal) condition. I only want it to come to this condition when i click on minimize button. Any Solution?

Abdul Ahad
  • 55
  • 1
  • 6
  • 2
    Possible duplicate of [How to trigger the event associated with maximize in C#](http://stackoverflow.com/questions/5885025/how-to-trigger-the-event-associated-with-maximize-in-c-sharp) – MethodMan Feb 15 '16 at 13:18
  • this question has been asked before if you do a simple google search you will find an example not to mention many others – MethodMan Feb 15 '16 at 13:18

1 Answers1

0

Your MainWindow class may override the OnPropertyChanged method to access the previous and the current value of the WindowState property:

protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
{
    base.OnPropertyChanged(e);

    if (e.Property == Window.WindowStateProperty)
    {
        var oldState = (WindowState)e.OldValue;
        var newState = (WindowState)e.NewValue;

        Debug.WriteLine("{0} -> {1}", oldState, newState);
    }
}
Clemens
  • 123,504
  • 12
  • 155
  • 268