C# – Maximize WPF Window on the current screen

cnetwindowswpf

I have a windowless wpf application, whenever I set the window state as maximized it maximizes it on the primary display.

What I would like to do is have it maximize on which ever display the application is running.

So any idea how I would do this?

My code at the moment is just

private void titleBarThumb_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (this.WindowState == System.Windows.WindowState.Normal)
            {
                this.WindowState = System.Windows.WindowState.Maximized;
            }
            else
            {
                this.WindowState = System.Windows.WindowState.Normal;
            }
        }

Best Answer

I've included this line on my MainWindow (first control) constructor:

Application.Current.MainWindow.WindowState = WindowState.Maximized;