locked
Packaging Fonts

    Question

  • I have a core class library where i would like to package all of my resources.  I have a set of fonts sitting in the directory "CoreProject\Fonts".  When i deploy my app i also see the directory "Project\CoreProject\Fonts" (located at C:\Users\user\AppxLayouts\). 

    I can't seem how to reference the font in a resource dictionary.  I have tried the following uri's:

    ms-resource://CoreProject/Files/Fonts/LTe50011.ttf#AvantGarde LT Book

    ms-resource://Files/Fonts/LTe50011.ttf#AvantGarde LT Book

    ms-resource://Fonts/LTe50011.ttf#AvantGarde LT Book

    CoreProject/Fonts/LTe50011.ttf#AvantGarde LT Book

    /Fonts/LTe50011.ttf#AvantGarde LT Book

    Fonts/LTe50011.ttf#AvantGarde LT Book

     

    And none of them seem to find the font.  Also it loads a default font (instead of throwing an exception).

     

    When i include the fonts in my host project everything works.  My goal is to embed all of the resources in a core project.

    Monday, September 26, 2011 3:08 PM

Answers

All replies

  • What are their Build Action? Since the URIs means the Fonts is built as the embed resources.

    Please try to set the Font files Build Action as Resources (note, the Resources and the Embeded Resources are different, we should set it as the former).

    And I suggest your to reflect the compiled assembly, and check its resources in it.


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, September 26, 2011 5:30 PM
  • Bob,

    There isn't an option to set the font as a "Resource". Also, it was suggested in another thread (by chipalo) to set the build action to 'Content' which i have done.

    I also checked the directory "C:\Users\carteada\AppxLayouts\{appDirectory}" and the fonts ARE in there under "{appDirectory}\CoreProject\Fonts".  The problem is that i don't know the URI to reference the font path.  Any path i try seems to be silently ignored.

     

    Now, I can reference the fonts if i include them in my main project but i want to be able to stick all of my resources in one single assembly.

    Monday, September 26, 2011 5:46 PM
  • Oh, yes, you are right.

    I make a sample to use one font file in an assembly, like this:

    <TextBlock Text="Test" FontFamily="ms-resource://ClassLibrary1/Files/Resources/BuxtonSketch.ttf#Buxton Sketch" FontSize="30"/>
    


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, September 27, 2011 5:04 PM