简体   繁体   English

如何创建具有精确像素大小的WPF窗口?

[英]How to create WPF window with exact pixel size?

I try to display a window in my application exactly in specified rectangle: 我尝试在应用程序中完全以指定的矩形显示一个窗口:

Left = 0, Top = 0, Width = 1920, Height = 240 . Left = 0, Top = 0, Width = 1920, Height = 240

It seems to have left and right margin. 好像有左右边距。 And a bottom margin. 还有底边。 Looks roughly like 8 pixels. 看起来大致像8像素。 Like the system refused to place the window where I told it to by specifying Left, Top, Width and Height properties. 就像系统拒绝通过指定Left,Top,Width和Height属性将窗口放置在我告诉它的位置一样。

However when I set WindowStyle to None and AllowsTransparency to True - it behaves properly. 但是,当我将WindowStyle设置为None并将AllowsTransparencyTrue ,它会正常运行。

But I don't need and I don't want borderless windows, I need normal system windows, but placed correctly. 但是我不需要,也不需要无边界的窗口,我需要普通的系统窗口,但是放置正确。 How to achieve it? 如何实现呢?

If the margins are the part of Windows UI and can't be removed - how to determine their sizes to take into account when placing windows? 如果页边距是Windows UI的一部分并且无法删除-放置窗口时如何确定要考虑的边距大小?

I'm testing it with Windows 10 on desktop computer. 我正在台式机上的Windows 10上对其进行测试。

It's cause there is no design border in windows 10 like windows 7 . 这是因为windows 10windows 7一样没有设计边界。 Use below code to set the Left property: 使用以下代码设置Left属性:

Left = 0 - SystemParameters.ResizeFrameVerticalBorderWidth - SystemParameters.FixedFrameVerticalBorderWidth;

your window's position will be right after this. window's位置将在此之后。 Top should be already OK. 顶部应该已经可以了。 Set Width equal to SystemParameters.WorkArea.Width then there should be no margin to Right. 设置Width等于SystemParameters.WorkArea.Width那么Right不应有空白。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM