sci chart
sci chart

Reputation: 53

Adding custom font in silverlight

I tried to add google font to my silverlight project. so i downloaded the zip and added the fonts to Fonts folder: enter image description here

I tried to load it like this:

<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}" />

and nothing happened. what should i do to fix this?

thanks!

Upvotes: 2

Views: 554

Answers (2)

Nkosi
Nkosi

Reputation: 247088

If you are using windows, Open the font you want to use with Windows Font Viewer

Check the Font name:. That name is what you will use when referencing it. Note: the font name may not always match the filename of the .ttf and can also include spaces.

You want to make sure that the `Build Action' of the included file in the project is set to Resource as you want to be able to reference it from xaml.

You can create a static resource for the FontFamily in your App.xaml so you can reference it throughout your project.

Assuming the name of the assembly for your project is 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 -->

Then build the project.

From there you should be able to reference it like so

<controls:DynamicTextBlock Grid.Column="2"
    Width="200"
    HorizontalAlignment="Left"
    FontSize="{StaticResource FontSize6}"
    FontFamily="{StaticResource RobotoLightFontFamily}"
    Foreground="White"
    Text="{Binding UserFullName}"
    ToolTipService.ToolTip="{Binding UserFullName}" />

Reference:

How to use your own fonts within Silverlight

Using Custom Fonts in Silverlight

Using built-in, embedded and streamed fonts in Silverlight

Upvotes: 2

matt
matt

Reputation: 333

If you can, check what the display name of the font is, instead of the file name for the part after the #. It may actually be Roboto Light.

<controls:DynamicTextBlock FontFamily="/EZTrader;component/Fonts/RobotoLight.ttf#Roboto Light" />

You may also need to change the build properties on your font file as seen here: http://geekswithblogs.net/mamta_m/archive/2010/07/01/adding-custom-fonts-to-your-silverlight-application.aspx.

Upvotes: 0

Related Questions