DCSIMG
How To: Font Embedding In Silverlight - Itai Goldstein

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:

  1. Add the font file to your application and set the Build Action to Resource:
    image
  2. 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:

image

Hope you find it useful.

Published Sunday, May 10, 2009 2:19 PM by itai
תגים:,

Comments

# How To: Font Embedding In Silverlight

You've been kicked (a good thing) - Trackback from DotNetKicks.com

Sunday, May 10, 2009 2:25 PM by DotNetKicks.com

# re: How To: Font Embedding In Silverlight

You saved me from a headache with this post. Many thanks!

Tuesday, May 12, 2009 7:11 PM by Jeffrey L. Albertson

# Silverlight calibri | 360inconline

Pingback from  Silverlight calibri | 360inconline

Thursday, December 15, 2011 8:45 AM by Silverlight calibri | 360inconline

Leave a Comment

(required) 
(required) 
(optional)
(required) 

Enter the numbers above: