Properly maximizing WPF window with WindowStyle=None

后端 未结 5 1244
孤街浪徒
孤街浪徒 2020-12-24 14:50

There are two problems with WPF windows when the WindowStyle=None option is used.

  1. The window covers the Taskbar when maximized.
  2. Once maximized, the wi
5条回答
  •  伪装坚强ぢ
    2020-12-24 15:29

    If only one monitor is used another simple approach is to set the maximum height of the window. The System.Windows.SystemParameters class provides some usefull values e.g. PrimaryScreenHeight or MaximizedPrimaryScreenHeight.

    In my sample code i use MaximizedPrimaryScreenHeight and subtract the ResizeBorderThickness i set in WindowChrome.

    using System.Windows;
    using System.Windows.Shell;
    
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
    
            Thickness resizeBorderThickness = WindowChrome.GetWindowChrome(this).ResizeBorderThickness;
            this.MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight - resizeBorderThickness.Top - resizeBorderThickness.Bottom;
        }
    }
    

提交回复
热议问题