Embed a font

If you want to embed a font into your Silverlight applications, add the font into your project:

image

Set the Build Action file property to embedded resource:

image

Use the following code snippet to use the font as a font source for your components:

Assembly ass = Assembly.GetExecutingAssembly();
Stream stream =
ass.GetManifestResourceStream("EmbeddedResource.Font.pricedow.ttf");
this.test.FontSource = new FontSource(stream);
this.test.FontFamily = new FontFamily("Pricedown");

XAML looking something like:

<Grid x:Name="LayoutRoot" Background="White">
    <Canvas>
        <TextBlock x:Name="test" FontFamily="annifont.ttf#Annifont" 
         Text="grand theft auto IV" FontSize="30"/>    
    </Canvas>    
</Grid>

And the result:

image

Source:

http://cid-bdfb7845c22e26b6.skydrive.live.com/embedrow.aspx/Projects/EmbeddedResource.zip

Leave a comment