为什么运行时窗口会变大?

发布于 2024-10-15 02:53:05 字数 1233 浏览 5 评论 0原文

我的窗口设置为 340 x 146 像素,无法调整大小。

在设计器中,窗口大小是正确的。但当我运行该应用程序时,它更大。 在此处输入图像描述

编辑:此外,布局是 Canvas

经典主题:

在此处输入图像描述

Edit2:

运行 snoop 后(感谢 Zach),看来实际尺寸是我指定的。 但客户区比 Visual Studio 中的客户区要大。

我现在明白,当窗口大小固定为某些尺寸时,客户端大小会拉伸。不过我认为这使得窗口中的 Canvas 布局无法使用。

编辑3:

<Window x:Class="TI.Presentation.Views.AutentizationWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Authentication" Height="146" Width="340" ResizeMode="NoResize" Background="{StaticResource {x:Static SystemColors.ControlBrushKey}}" >
    <Canvas>
        <Label Canvas.Left="12" Canvas.Top="12" FontSize="15" Width="217">Enter authentication code here:</Label>
        <TextBox Canvas.Left="12" Canvas.Top="38" Height="23" Name="code" Width="294" FontSize="14" />
        <Button Canvas.Top="67" Content="OK" Height="28" Width="100" Canvas.Left="206" FontSize="14" IsDefault="True" Click="OKClick" />
    </Canvas>
</Window>

I have a window set to 340 x 146 px, not resizable.

In designer the window size is correct. But when I run the application it is bigger.
enter image description here

Edit: Also, the layout is Canvas.

Classic theme:

enter image description here

Edit2:

After running snoop (thanks Zach), it appears that actual dimensions are what I specified.
But the client area is bigger than one in visual studio.

I understand now that the client size stretches, when windows size is fixed to certain dimensions. However I think this makes Canvas layout in window unusable.

Edit3:

<Window x:Class="TI.Presentation.Views.AutentizationWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Authentication" Height="146" Width="340" ResizeMode="NoResize" Background="{StaticResource {x:Static SystemColors.ControlBrushKey}}" >
    <Canvas>
        <Label Canvas.Left="12" Canvas.Top="12" FontSize="15" Width="217">Enter authentication code here:</Label>
        <TextBox Canvas.Left="12" Canvas.Top="38" Height="23" Name="code" Width="294" FontSize="14" />
        <Button Canvas.Top="67" Content="OK" Height="28" Width="100" Canvas.Left="206" FontSize="14" IsDefault="True" Click="OKClick" />
    </Canvas>
</Window>

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

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

发布评论

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

评论(4

微凉徒眸意 2024-10-22 02:53:05

我将在探索后亲自回答这个问题。

窗口的ActualWith和ActualHeight等于设计器中设置的宽度和高度。

变化的是客户区。客户端的尺寸将是窗口尺寸减去主题边框。然而,这打破了画布设计,因为它的绝对定位和画布尺寸根据主题而改变。

让 Canvas 设计发挥作用的方法。是在 Canvas 上设置尺寸,删除窗口上的尺寸并相应地在窗口上设置 SizeToContent。这样,cavnas 尺寸保持固定,窗口大小根据主题边框的想法而变化。

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.

药祭#氼 2024-10-22 02:53:05

只是因为您指定的大小不考虑将从操作系统当前主题中获取的边框...如果您设置 200x200,您将获得完整的空间..您不希望将其缩小到 190x190 框因为两边都有 5px 边框。这也将更改为操作系统的当前主题,例如 Aero、Classic 等。

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.

庆幸我还是我 2024-10-22 02:53:05

窗口是否设置了 DesignHeightDesignWidth?请参阅 WPF 用户控件设计时间大小

编辑:我的下一个想法是尝试使用 Snoop 在运行时查看什么完全不同。是大小、填充、边距还是其他什么?

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?

伤痕我心 2024-10-22 02:53:05

我可能说的是显而易见的事情,但 Windows 主题似乎是差异所在。如果您切换到 Windows 经典主题,它们会如何比较。

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.

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