Why is a window larger in runtime?

大兔子大兔子 提交于 2019-12-05 00:28:24

I'm going to answer this myself after poking around.

The window's ActualWith and ActualHeight are equal to Width and Height set in the designer.

What changes, is the client area. The dimensions of client are will be window dimensions minus theme border. This, however, breaks Canvas design because its absolutely positioned and canvas dimensions changed based on theme.

The way to make Canvas design work. Is to set dimensions on Canvas, remove dimensions on window and set SizeToContent on window accordingly. This way, cavnas dimensions stay fixed and Window size changes based on how think the theme border is.

Simply because the size u specify dosent take into account the border which will be taken from the Operating System's current Theme... If you are setting 200x200 you are getting that full space.. you wouldn't want it to be reduced to 190x190 box because of 5px border either side. and that too will change to the Current Theme on the Operating System, like Aero, Classic, etc.

Zach Johnson

Does the window have a DesignHeight and DesignWidth set? See WPF UserControl Design Time Size.

Edit: My next thought would be to try using Snoop to see at runtime what exactly is different. Is it the size, the padding, the margin, or something else?

I'm probably stating the obvious, but it appears that the Windows theme is the difference. How do they compare if you switch to Windows classic theme.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!