WPF 标签在 XP 中看起来不错,但在 Vista 和 Windows 7 中底部被切断
下面的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据 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)