WPF 在 Windows 7 和 Windows 8 之间的 TextBlock 差异 [英] WPF's TextBlock differences between Windows 7 and Windows 8

查看:32
本文介绍了WPF 在 Windows 7 和 Windows 8 之间的 TextBlock 差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在调查一些仅在我的机器上失败的单元测试时,我注意到 TextBlock 在 Windows 7 和 Windows 8 机器上显示文本的方式不同.为了检查该问题,我创建了仅包含一个 TextBlock 的示例应用程序:

While investigating some unit tests which fail only on my machine, I noticed that TextBlock presents text differently on Windows 7 and Windows 8 machines. To inspect the issue, I created sample application containing just one TextBlock:

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <TextBlock Text="yo" FontSize="100" FontFamily="Verdana" />
    </Grid>
</Window>

您可以看到(或者至少我希望如此)Windows 7 上的文本长 1px - 实际上y"和o"之间的字距增加了 1px:

You can see (or at least I hope so) that the text on Windows 7 is 1px longer - actually the kerning between the "y" and "o" is 1px thicker:

我使用字体阅读器软件检查了两台机器上的 Verdana.ttf 字体文件,其中列出的y"和o"之间的字距调整是相同的:-18.
还检查了 .NET Framework 的版本,它们也是相同的:4.5.50709.
...我仍然想知道是什么导致了这种差异?

I inspected the Verdana.ttf font files on both machines with a font reader software, and the kerning between "y" and "o" listed there is one and the same: -18.
Also checked the versions of the .NET Framework, which are also identical: 4.5.50709.
...and I am still wondering what causes this difference?

推荐答案

我更愿意认为这与 ClearType 或 Anti-Aliasing 有关,Microsoft 在每个 Windows 版本之间不断更改该代码.不要认为您对此无能为力,只需要将这些差异考虑到您的单元测试中即可.

I'd rather think it is something to do with ClearType or Anti-Aliasing, Microsoft is constantly changing that code between every Windows release. Don't think there is anything you can do about that, just have to factor in those differences to your unit tests.

这篇关于WPF 在 Windows 7 和 Windows 8 之间的 TextBlock 差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆