我尝试将谷歌字体添加到我的 silverlight 项目中。所以我下载了 zip 并将字体添加到 Fonts 文件夹中:
我尝试像这样加载它:
<controls:DynamicTextBlock Grid.Column="2"
Width="200"
HorizontalAlignment="Left"
FontSize="{StaticResource FontSize6}"
FontFamily="/EZTrader;Component/Fonts/#RobotoLight"
Foreground="White"
Text="{Binding UserFullName}"
ToolTipService.ToolTip="{Binding UserFullName}" />
什么也没发生。 我应该怎么做才能解决这个问题?
谢谢!
最佳答案
如果您使用的是 Windows,请使用 Windows 字体查看器
打开您要使用的字体
检查字体名称:
。该名称是您在引用它时将使用的名称。 注意:字体名称可能并不总是与.ttf
的文件名匹配,并且还可以包含空格。
您需要确保项目中包含的文件的“构建操作”设置为资源,因为您希望能够从 xaml 引用它。
您可以在 App.xaml 中为 FontFamily 创建静态资源,以便可以在整个项目中引用它。
假设您的项目的程序集名称是 EzTrader.dll
<FontFamily x:Key="RobotoLightFontFamily">/EzTrader;component/Fonts/RobotoLight.ttf#[Font name here]</FontFamily>
<FontFamily x:Key="RobotoThinFontFamily">/EzTrader;component/Fonts/Roboto-Thin.ttf#[Font name here]</FontFamily>
<!-- other font resources -->
然后构建项目。
从那里你应该能够像这样引用它
<controls:DynamicTextBlock Grid.Column="2"
Width="200"
HorizontalAlignment="Left"
FontSize="{StaticResource FontSize6}"
FontFamily="{StaticResource RobotoLightFontFamily}"
Foreground="White"
Text="{Binding UserFullName}"
ToolTipService.ToolTip="{Binding UserFullName}" />
引用:
How to use your own fonts within Silverlight
关于c# - 在 silverlight 中添加自定义字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36202457/