×

Discussion Board

Results 1 to 7 of 7

Hybrid View

  1. #1
    Registered User
    Join Date
    Feb 2007
    Location
    Tampere
    Posts
    370

    Multiple Dynamic Font loading

    Hi,

    I wanted to load multiple fonts dynamically on a single page. I have been able to load single font, but trying to load multiple fonts results in falling back to default font. Does anyone know how to do that.

    I need this as I wrote a multi lingual application whose entry point should display text for all the languages I am supporting.
    Ofcourse I can achieve this by making images, but text would be convenient.
    Regards

    - MVP
    "Dare To Dream" - A.P.J.Kalam

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2011
    Location
    Portugal
    Posts
    921

    Re: Multiple Dynamic Font loading

    if these are fonts that you package with your app you need to:

    - Add the font to a folder on your app
    - Change the properties of the font file to: Build Action: Content; Copy to output directory: Copy if newer


    Then to use the font on your project, in xaml:

    <TextBlock Text="Sample text with a different font" FontFamily="fonts/nameofthefont.ttf#nameofthefont" FontSize="60"/>
    The name after the # is the actual Font name.

  3. #3
    Registered User
    Join Date
    Feb 2007
    Location
    Tampere
    Posts
    370

    Re: Multiple Dynamic Font loading

    Hi Joao,

    Thanks this approach works.
    May be I should have phrased the question in a better way earlier. I think, I had done too many changes to code and saw some other problem.
    But Here is my attempt two with more focused problem

    I would like to load the font dynamically rather than hard code into the xaml.
    For eg:
    I am loading font for whole page like this ...
    PageTitle.FontFamily = new FontFamily("<new font name>"); PageTitle.Text = "<some text in the new font>"
    This works.
    Similarly I would like to do the same for textblock.
    TextBlk.FontFamily = new FontFamily("<new font name>"); TextBlk.Text = "<some text in the new font>"

    But the compiler throws error saying "System.Windows.Controls.Control.FontFamily is a property but is used like a type."

    Any idea what is wrong here?

    Why I need this - I can add/remove languagues and text blocks on the fly, rather than compile the code everytime.
    Just pick languages from server and push them down with some logic ofcourse

    Regards

    Mrudul
    Regards

    - MVP
    "Dare To Dream" - A.P.J.Kalam

  4. #4
    Nokia Developer Champion
    Join Date
    Sep 2012
    Location
    Morocco
    Posts
    292

    Re: Multiple Dynamic Font loading

    I just compiled a project with the same line of code as this one, without any problem.
    Code:
    TextBlk.FontFamily = new FontFamily("<new font name>"); TextBlk.Text = "<some text in the new font>";
    Do you use the normal TextBlock Control ? or have you made a custom one ?

  5. #5
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,572

    Re: Multiple Dynamic Font loading

    Perhaps the namespace (System.Windows.Media) is not used in the scope for the problematic code.

  6. #6
    Registered User
    Join Date
    Feb 2007
    Location
    Tampere
    Posts
    370

    Re: Multiple Dynamic Font loading

    Hmm,

    Yep, System.Windows.Media; was indeed a problem. Strange I donot remember adding the same namespace for other page.
    Anyways... thanks for the solution.
    Regards

    - MVP
    "Dare To Dream" - A.P.J.Kalam

Similar Threads

  1. Do you think that dynamic jar loading is possible ??
    By gizyy in forum Mobile Java General
    Replies: 4
    Last Post: 2010-04-20, 15:06
  2. dynamic image loading
    By mfcguru in forum Mobile Java General
    Replies: 3
    Last Post: 2005-11-30, 13:56
  3. Dynamic class loading
    By rainersimon in forum Symbian
    Replies: 0
    Last Post: 2005-04-28, 09:31
  4. Dynamic loading and converting to MBM
    By whitemoon in forum Symbian User Interface
    Replies: 3
    Last Post: 2003-11-04, 04:39
  5. dynamic loading of icons?
    By ssseko in forum Symbian User Interface
    Replies: 0
    Last Post: 2003-08-12, 16:26

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •