Maximize WPF Window on the current screen

后端 未结 10 684
谎友^
谎友^ 2021-01-31 07:35

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

相关标签:
10条回答
  • 2021-01-31 08:07

    We cannot maximize the window until it's loaded. So by hooking the Loaded event of fullScreenWindow and handling the event along the lines of:

    private void Window_Loaded(object sender, RoutedEventArgs e) 
    {
        WindowState = WindowState.Maximized;
    }
    
    0 讨论(0)
  • 2021-01-31 08:07

    I just ran into the same problem. In my case it turned out to be the fact that I was Hiding my pop up window when I was done with it. So if I called it next time and asked it to Maximize, it would do it on the original screen. Once I started Closing it instead, it started to maximize on the proper screen.

    0 讨论(0)
  • 2021-01-31 08:09

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

    Application.Current.MainWindow.WindowState = WindowState.Maximized;
    
    0 讨论(0)
  • 2021-01-31 08:09

    c# application first starts on the primary display, unless it is moved your code will work. However, if your wpf app will be moved to another display new location can be recorded and stored in a local config file. But, your app will have no borders or any other native controls so you will also have to implement the moving bit. and when your window is moved you will be able to capture the display index using SystemParameters.

    Good Luck

    0 讨论(0)
  • 2021-01-31 08:21

    Because of the taskbar you should use user working area's size:

    this.Width=SystemParameters.WorkArea.Width;
    this.Height=SystemParameters.WorkArea.Height;
    

    You can use this in view's constructor

    0 讨论(0)
  • 2021-01-31 08:21

    I asked a similar question that you might find helpful. How Can I Make a WPF Window Maximized on the Screen with the Mouse Cursor?

    0 讨论(0)
提交回复
热议问题