全屏 WPF 应用程序的分辨率

发布于 2024-12-14 04:26:55 字数 432 浏览 3 评论 0原文

按照此处的指南,我创建了一个全屏WPF 应用程序。但我遇到了一个问题:各种尺寸&屏幕的分辨率。例如,我想在屏幕上放置几个精灵作为按钮;但它们在每个屏幕中的位置不同,甚至与 XAML 设计器中显示的位置不同。

我到处寻找却没有任何线索。我该如何解决这个问题? (让按钮出现在准确的位置(中心),更好的是,帮助 xaml 设计者准确反映程序运行时会发生什么)。任何帮助将不胜感激。

更新:我将我的页面定义为Window元素内的Canvas。事实上我更喜欢Canvas,因为我可以轻松地将我的精灵放在任何地方,而不是像网格那样。

Following the guide here, I have created a full-screen WPF application. But I met a problem: the various size & resolution of screens. For example, I want to put several sprites on the screen as buttons; but they are located at different positions in each screen, and even different to what shown in the XAML designer.

I have searched all over without a clue got. How can I fix this problem? (to make the buttons appears the exact place (in the center), and better, help the xaml designer reflect exactly what will happens when the program is running). Any help will be appreciated.

UPDATE: I'm defining my page as a Canvas inside the Window element. Actually I like Canvas more, cause I can easily put my sprites anywhere, not like a grid.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

平定天下 2024-12-21 04:26:55

通常,不应在 WPF 中使用像素值。

相反,您应该使用行和列在 中布局内容,它会自动扩展以填充屏幕(基于对齐方式和行/列定义)。

In general, you should not use pixel values in WPF.

Instead, you should layout your content in <Grid>s with rows and columns, and it will automatically expand to fill the screen (based on the alignments and row / column definitions).

嘿咻 2024-12-21 04:26:55

避免使用画布。另外,不要过多依赖设计师来构建布局。使用网格、堆栈面板和/或 Dockpanels 将提供更好的结果(并在调整窗口大小时进行缩放)。例如,如果您仅使用设计器并拖放所有元素,则设计器通常会随机地放置巨大的边距,并且如果您调整窗口大小,这并不总是能够正确缩放。

Avoid using the canvas. Also, do not rely too much on the designer to build your layout. Using Grids, Stackpanels and/or Dockpanels will give much better results (and scale when resizing your window). For example, if you use only the designer and drag-and-dropp all your elements, the designer often puts huge margins a bit randomly and this will not always scale properly if you resize your window.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文