WPF full screen on maximize

后端 未结 9 1872
醉话见心
醉话见心 2021-02-04 12:56

I basically want to have my WPF window to go in full screen mode, when F11 is pressed or the maximize button in the right top corner of the window is pressed.

While the

相关标签:
9条回答
  • 2021-02-04 13:12

    You need to set the Window.Topmost property.

    Edit

    Check this blog post Maximizing window (with WindowStyle=None) considering Taskbar

    0 讨论(0)
  • 2021-02-04 13:13

    WPF seems to be making the decision about whether to go full-screen or respect the taskbar based on the WindowStyle at the time of maximisation. So a kludgy but effective solution is to switch the window back to non-maximised, set the WindowStyle, and then set the window back to maximised again:

    private bool _inStateChange;
    
    protected override void OnStateChanged(EventArgs e)
    {
      if (WindowState == WindowState.Maximized && !_inStateChange)
      {
        _inStateChange = true;
        WindowState = WindowState.Normal;
        WindowStyle = WindowStyle.None;
        WindowState = WindowState.Maximized;
        ResizeMode = ResizeMode.NoResize;
        _inStateChange = false;
      }
      base.OnStateChanged(e);
    }
    

    Although the code is obviously ugly, the transition to Normal and then back to Maximized doesn't seem to make the user experience any worse. On my display, I noticed flicker with both the F11 code and the kludge maximise, but not noticeably worse on the kludge maximise. But your mileage may vary!

    0 讨论(0)
  • 2021-02-04 13:17

    try this

    Topmost="True" and WindowState="Maximized"
    

    you can see your window will cover all screen and hide all with windows taskbar

    0 讨论(0)
  • 2021-02-04 13:19

    Another solution that worked for me:

    You can set the MaxHeight property of that window to SystemParameters.MaximizedPrimaryScreenHeight using the constructor.

    public MainWindow()
    {
        InitializeComponent();
        this.MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight;
    }
    

    Warning: This might not work on extended desktop.

    Source: Maximize window with WindowState Problem (application will hide windows taskbar)

    0 讨论(0)
  • 2021-02-04 13:19

    If you happen to be using WindowChrome to create a custom chrome experience, you'll need to set the GlassFrameThickness to something other than 0 (at least that was the last thing I needed to do to get the TaskBar to be hidden behind the window). That is in addition to the steps provided in the accepted answer.

    0 讨论(0)
  • 2021-02-04 13:19

    In my case, minimizing and maximizing will make the fullscreen size to be a little bit bigger than the screen, so the alternative I found is to temporarily set the Visibility to Collapsed then back to Visible afterwards to force redraw.

    Visibility = Visibility.Collapsed;
    WindowStyle = WindowStyle.None;
    WindowState = WindowState.Maximized;
    ResizeMode = ResizeMode.NoResize;
    Visibility = Visibility.Visible;
    
    0 讨论(0)
提交回复
热议问题