Adding a custom font in a Silverlight application

How to add a custom font to your application:

It is possible to include custom fonts in a application.

The procedure for importing and using a custom font is described below:

1.      In the Solution Explorer, right click on the Silverlight application project name and choose “Add->New Item…”  from the context menu.

2.      Select the custom font after navigating to the directory in which it is present and click OK.

3.      In the property grid of the font, specify the Build Action = “Resource” and the “Copy to Output Directory” = “Copy if newer”:

4.      In the XAML code, reference the font by using syntax as shown below:

   FontFamily=”[AssemblyShortName];component/[FontFileName]#[FontFriendlyName]”

Example: check the portion marked in yellow

 <TextBlock Text="This is a font test" FontFamily = "Calibri.ttf#Calibri"></TextBlock>

Ebook Download
View all
Learn
View all