How to trigger the event associated with maximize in C#

Shamim Hafiz picture Shamim Hafiz · May 4, 2011 · Viewed 8.3k times · Source

Consider the following code:

Window myWindow = new MyWindowSubclass();
myWindow.BringIntoView();
myWindow.Show();

// Code which is effective as pressing the maximize button

Also, how to detect if the window is indeed in maximized state.

Answer

Frédéric Hamidi picture Frédéric Hamidi · May 4, 2011

In WPF, you can use the WindowState property:

myWindow.WindowState = WindowState.Maximized;

You can of course query that property to obtain the current window state:

if (myWindow.WindowState == WindowState.Maximized) {
    // Window is currently maximized.
}