How To: Font Embedding In Silverlight
Silverlight includes nine basic core fonts (these fonts can be rendered correctly on any browser and operating system Silverlight supports):
- Arial
- Arial Black
- Comic Sans MS
- Courier New
- Georgia
- Lucida Grande / Lucida Sans Unicode
- Times New Roman
- Trebuchet MS
- Verdana
But what can you do when you like to use another font which is not included in the core fonts list?
The answer is embedding the desired font in your Silverlight application:
- Add the font file to your application and set the Build Action to Resource:
- Set the FontFamily property in the following format: FontFileName#FontName
<TextBlock Text="This is Calibri Font"
FontFamily="CALIBRI.TTF#Calibri"
FontSize="20">
</TextBlock>
Or you can achieve the same effect in the code behind:
StreamResourceInfo sri = Application.GetResourceStream(
new Uri("SilverlightApplication1;component/CALIBRI.TTF",
UriKind.Relative));
TextBlock1.FontSource = new FontSource(sri.Stream);
TextBlock1.FontFamily = new FontFamily("Calibri");
And here’s the result:
Hope you find it useful.