最近我需要实现一个名为Roboto的谷歌字体的WPF项目。 然后我在互联网上搜索了一些方法。 有很多方法可以在我的项目中添加它,所以我决定尝试所有这些,特别是那些被投票的。 首先,我从谷歌下载了Toboto字体。 其次,我将一个Toboto-Regular.ttf添加到Resources.resx,并将Build更改为'Resource'。 最后,我在UserControl.xaml中添加了一些标签来测试它们。 这是代码:
<StackPanel>
<Label x:Name="label1" Content="Maintenance" FontFamily="/myAPP1;component/Resources/#Roboto" FontSize="16"/>
<Label x:Name="label2" Content="Maintenance" FontFamily="pack://application:,,,/Resources/#Roboto" FontSize="16"/>
<Label x:Name="label3" Content="Maintenance" FontFamily="Roboto-Regular" FontSize="16"/>
<Label x:Name="label4" Content="Maintenance" FontFamily="Roboto" FontSize="16"/>
<Label x:Name="label5" Content="Maintenance" FontFamily="./Resources/#Roboto" FontSize="16"/>
<Label x:Name="label6" Content="Maintenance" FontFamily="Arial" FontSize="16" />
<Label x:Name="label7" Content="Maintenance" FontSize="16" />
</StackPanel>
label1字体是从Property-Text-FontFamily-Roboto中选择的,它不是我自己编码的。 label2-5是我在互联网上找到的方式。标签6和7作为对比放在那里。 很快我发现label1&amp; 2是相同的,label3-5是相同的,label6&amp; 7正是它们应该是的。 这是图像: Label1-7 image 然后我想到了FontFamily标签3-5究竟是什么?他们是Roboto-Light吗?所以我将Roboto-Light.ttf添加到我的资源中并再次从Property中选择,你可以想象,它与label3-5不同。 这是代码:
<Label x:Name="label8" Content="Maintenance" FontFamily="/myAPP1;component/Resources/#Roboto Light" FontSize="16" />
这是图像: Labels with fontfamily image 为了解决这个问题,我在这里发布问题,等待你的答案。非常感谢!