Mattias Sturebrand Mattias Sturebrand - 1 month ago 15
C# Question

c# WPF SizeChanged event fires before main window is loaded

I´m a newbie in WPF

I want to detect when main window size changes (with mouse grip), but event is fired before main window is loaded at start of the application. How come it is so?

private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
{
MessageBox.Show("Window is Resized");
}

Answer

In first fire your previous size is 0,0 If you want to ignore it

You can try this:

private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
{
    if (e.PreviousSize != new Size())
    {
        MessageBox.Show("Window is Resized");
    }
}
Comments