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

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

问题描述

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>

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:

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?

解决方案

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 的 TextBlock 在 Windows 7 和 Windows 8 之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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