意见:Viewbox

发布于 2024-11-13 09:05:59 字数 1264 浏览 9 评论 0原文

我不想在 WPF Windows 应用程序中处理不同的屏幕分辨率。因此,我找到了一种方法,我相信它可以在合理范围内解决显示的所有各种问题。

窗口的设计是这样的:

<Window x:Class="MyWindow.Window3"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="872" Title="My Window" SizeToContent="Manual" WindowState="Maximized" d:DesignWidth="1242"
        Height="768" Width="1024" VerticalAlignment="Stretch" Closing="Window_Closing" Icon="Icon.ico" WindowStyle="ThreeDBorderWindow">

    <Grid>
        <Viewbox HorizontalAlignment="Left" VerticalAlignment="Top" StretchDirection="Both">
<!-- your controls go here -->

        </Viewbox>
    </Grid>
</Window>

通过这种方法,无论分辨率如何,窗口都会缩放以与显示器对齐。存在一些应该提及的极端情况;

  • 如果窗口最小化到非常小的分辨率,它将无法使用,因为控件会急剧缩小。

  • 如果窗口的设计宽高比与目标不同,则可能会显示大量空白

除了指出的潜在负面约束之外,我对此时的结果非常满意。我不需要担心滚动条或各种缩放选项 - 它就可以了!

我不是第一个发现这一点的人,但我以前从未在任何地方看到过这种方法。我仍然是 C# 世界的新手,这是最近的发现。

我想听听我在这里没有考虑到的方法的负面影响,并希望这将有助于其他人的设计工作。

感谢大家......

I don't want to deal with varying screen resolutions in a WPF windows app. So, I came upon an approach which I believe deals with all of the various issues of the display - within reason.

The design of the window goes like this:

<Window x:Class="MyWindow.Window3"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="872" Title="My Window" SizeToContent="Manual" WindowState="Maximized" d:DesignWidth="1242"
        Height="768" Width="1024" VerticalAlignment="Stretch" Closing="Window_Closing" Icon="Icon.ico" WindowStyle="ThreeDBorderWindow">

    <Grid>
        <Viewbox HorizontalAlignment="Left" VerticalAlignment="Top" StretchDirection="Both">
<!-- your controls go here -->

        </Viewbox>
    </Grid>
</Window>

With this approach, the window is scaled to align to the display, regardless of the resolution. There are corner cases, which should be mentioned;

  • If the window is minimized to a very small resolution, it will be unusable, as the controls are dramatically scaled down.

  • If the window is designed in a different aspect ratio than the target, then there is likely to be a large amount of whitespace displayed

Apart from the potential negative constraints called out, I am very happy with the results at this point. I don't need to worry about scrollbars, or various scaling options - it just works!

I can't be the first person to discover this, but I have not seen this approach mentioned anywhere before. I am still a newbie in the world of C#, and this is a recent discovery.

I would like to hear about negatives to the approach which I have not considered here, and hope that this will help others in their design efforts.

Thanks to all......

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

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

发布评论

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

评论(1

红玫瑰 2024-11-20 09:05:59

元素有多大应该由用户选择。他可以更改 DPI 或分辨率(尽管对于 LCD 来说这可能不是一个好主意,但对于 CRT 来说效果很好)。如果他希望能够以较小的字体看到大量信息,那就让他这样做吧。

如果他的显示屏很小,您应该显示滚动条,而不是难以辨认的小字体。

It should be the user's choice how big the elements are. He can change the DPI or the resolution (although this may not be such a good idea with LCDs, it worked well with CRTs). If he wants to be able to see lots of information in smaller font, let him do it.

If he has tiny display, you should display scrollbars, not illegibly small font.

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