如何创建具有精确像素大小的 WPF 窗口? [英] How to create WPF window with exact pixel size?

查看:29
本文介绍了如何创建具有精确像素大小的 WPF 窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在我的应用程序中完全在指定的矩形中显示一个窗口:

I try to display a window in my application exactly in specified rectangle:

左 = 0,顶部 = 0,宽度 = 1920,高度 = 240.

它似乎有左右边距.和底部边距.看起来大约是 8 像素.就像系统通过指定 Left、Top、Width 和 Height 属性拒绝将窗口放置在我告诉它的地方.

It seems to have left and right margin. And a bottom margin. Looks roughly like 8 pixels. Like the system refused to place the window where I told it to by specifying Left, Top, Width and Height properties.

但是,当我将 WindowStyle 设置为 None 并将 AllowsTransparency 设置为 True 时,它的行为正常.

However when I set WindowStyle to None and AllowsTransparency to True- it behaves properly.

但我不需要也不想要无边框窗口,我需要正常的系统窗口,但放置正确.如何实现?

But I don't need and I don't want borderless windows, I need normal system windows, but placed correctly. How to achieve it?

如果边距是 Windows UI 的一部分并且无法删除 - 如何确定它们的大小以在放置窗口时考虑?

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 10 对其进行测试.

I'm testing it with Windows 10 on desktop computer.

推荐答案

这是 因为在 windows 10 中没有设计边框,例如 <代码>Windows 7.使用以下代码设置 Left 属性:

It's cause there is no design border in windows 10 like windows 7. Use below code to set the Left property:

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

您的窗口位置将在此之后.顶应该已经OK了.将 Width 设置为等于 SystemParameters.WorkArea.Width 则右边应该没有边距.

your window's position will be right after this. Top should be already OK. Set Width equal to SystemParameters.WorkArea.Widththen there should be no margin to Right.

这篇关于如何创建具有精确像素大小的 WPF 窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆