Search code examples
c#wpfmaximize-window

How to trigger the event associated with maximize in C#


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.


Solution

  • 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.
    }