WPF 标签在 XP 中看起来不错,但在 Vista 和 Windows 7 中底部被切断

发布于 2024-09-05 02:45:25 字数 572 浏览 1 评论 0原文

下面的 xaml 在 XP 中看起来不错,但在 Vista 和 Windows 7 中文本的底部被截断。

<Grid>
    <Border Height="86"
            Margin="10,54,10,0"
            VerticalAlignment="Top"
            BorderBrush="Black"
            BorderThickness="1"/>
    <Label Height="22" 
           Width="100"
           Margin="15,43,0,0" 
           VerticalAlignment="Top" 
           HorizontalAlignment="Left"
           Background="White">Text Over Border</Label>
</Grid>

我意识到我可以增加标签的高度,但我猜我在使用具有以下功能的系统时会遇到问题不同的分辨率设置或大文本设置。有没有更好的方法来解决这个问题?

The following xaml looks fine in XP, but the bottom of the text gets cut off in Vista and Windows 7.

<Grid>
    <Border Height="86"
            Margin="10,54,10,0"
            VerticalAlignment="Top"
            BorderBrush="Black"
            BorderThickness="1"/>
    <Label Height="22" 
           Width="100"
           Margin="15,43,0,0" 
           VerticalAlignment="Top" 
           HorizontalAlignment="Left"
           Background="White">Text Over Border</Label>
</Grid>

I realize that I could just increase the Height of the label, but I'm guessing I'll have problems with systems that have different resolution settings, or large text settings. Is there a better way to lay this out?

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

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

发布评论

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

评论(1

做个ˇ局外人 2024-09-12 02:45:25

根据 juharr 的要求,我将添加我的评论作为答案,并进行简短的阐述:

为什么不直接自动调整标签的垂直大小?

在 WPF 中,很少需要像素值,特别是因为它们只是与设备无关的像素。对于任何文本(包括按钮),自动调整大小几乎总是正确的做法,特别是考虑到未来的本地化(很多人忘记了)。如果标签不打算自动换行,则始终自动调整垂直和水平尺寸。使用最小宽度以获得最佳视觉效果(对于按钮来说,最大宽度也可能是一件好事)

As requested by juharr, I'll add my comment as an answer, with a short elaboration:

Why not just auto-size the label vertically?

In WPF, there's rarely a need for pixel values, especially since they're just device-independent pixels anyway. For anything text (including buttons), auto-sizing is almost always the right thing to do, especially considering future localization (which many people forget). Auto-size always vertically, and horizontally if the label is not intended to be word-wrapped. Use a minimum width for best visual results (for buttons a maximum width may be a good thing as well)

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