Silverlight: Build Actions

Resources, embedded resources, content and all the other options! It’s just confusing! So I hope to outline the build actions so you can choose the best one to suit your needs

Silverlight Build Actions

Silverlight build actions defined:

  • None – Does exactly what it says on the tin (well textbox). The resource file will not be a part of the .xap.
  • Compile – This build action is reserved for .cs and .vb files and should not be used for other items.
  • Content – Item will be included in the application package (.xap) without it being embedded it in the project assembly.
  • Embedded Resource – This build action is aimed at non-Silverlight action. Should be changed to a build action of Resource
  • ApplicationDefinition – This build action is reserved for the app.xaml file which defines the start point for your Silverlight application.
  • Page – This build action is given to certain types of Xaml based files like user controls and pages. Mainly used with Silverlight navigation applications.
  • CodeAnalysisDictionary – Unknown.
  • Resource – The file is embedded into the application assembly. The resource is accessible using a relative Uri, relative to the Xaml file from where they are being referenced.
  • SplashScreen – Is for WPF applications only and is explained perfectly here.
  • EntityDeploy – is used by the ADO.NET Entity Framework.

Resource files and their related BuildAction alternatives are explained here.

If you have any comments or thoughts why not start a thread at Silverlight Forums?

Silverlight: How to obfuscate a font and use it in a Silverlight Application

You have your design almost in the bag, you have a font that you want to use but how can you use that font in Silverlight. Without distributing a font (which would be illegal unless you had a license to do this) requires you to obfuscate the font. Obfuscating the font means taking the font and converting it into an un-usable format outside your application.

So to convert you font follow this simple steps:

  1. Open up Word 2007
  2. Type every character, digit and symbol that you might need.
  3. Then select all the copy in the word document and change the font to the desired font.
  4. Save the document as an XPS file.
  5. Now close word and find the XPS file you have just created.
  6. Rename the file from .xps to .zip
  7. Now open that zip file and look inside the ‘Resources’ directory and you should see a file with the extension .odttf
  8. Copy the .odttf file into your Silverlight Application and set it’s build action to ‘Resource‘ (see our tutorial on Silverlight Build Actions)
  9. Now on a TextBlock in your page set the FontFamily location to your .odttf file

This is how you set the FontFamily on your TextBlock

The font name (the bold bit!) ‘Segoe UI‘ you see in the FontFamily path after the # needs to be exactly the same as what appears in your Word document dropdown list. This selects the font with the .odttf as you could have multiple fonts within the same .odttf file.

If you have any questions or need any help simply create a post at Silverlight Forums in the Fonts section.