The WPF window is maximized, the window is not close to the screen, and there is always a margin. What's going on?

when I make a WPF window, for some reason, I have to manually control the Maxheight of the window. When I set the MaxHeight of the window, click the maximize button, the window has maximized action, but not very close to the screen, there is always a blank of 3-5 pixels. As shown in the following figure:

if you remove the code that manually sets the window Maxheight, the window will snap to the screen normally when the window is maximized.

I would like to ask you how to solve this problem

May.12,2021

  1. you can try setting MaxHeight dynamically
  2. debug the UI, to see where the height and width of the maximized window differ from the values on the system screen.
Menu