0
votes

I have a Silverlight 4 Application that I run using Visual Studio 2012 Web Express. I added a CustomFont.zip in the Fonts folder of my project. the file is marked as "Resource".

When I use the font, in a TextBlock for example, I can see it in the Visual Studio XAML designer. But when I run the application it uses de default standard font.

Here's an example of my TextBlock

<TextBlock FontFamily="/Fonts/CustomFont.zip#MyFontName" >Hello World</TextBlock>

I have tried with embedded Zip like the example above. I also tried the font directly (without zip). Tried with TTF and OTF Font. Always same result I can see it at design time but not at runtime.

Thanks

2

2 Answers

1
votes

I'm sure you have this working by now but I had the same problem. I got it to work by formatting my FontFamily string like below and you definitely don't want the file to be in a zip file. I have my font in a project folder I created called "Fonts".

<TextBlock FontFamily="./Fonts/MyFontName.ttf#MyFontName" >Hello World</TextBlock>
1
votes

I also had same problem and I solved like below. I had to go through a lot of forums including this but none works. But some forum asked me to forcibly load font before I come to point of my interest.

In my TextBlockStyles.xaml resource dictionary I created a styke

<Style x:Key="RadWindowTitleTextStyle"
         TargetType="TextBlock">
      <Setter Property="Foreground"
            Value="#FFB9D449" />
      <Setter Property="FontSize"
            Value="18.667" />
      <Setter Property="FontFamily"
            Value="/sampleawebsite.application;component/Assets/Fonts/UBSHead.ttf#UBSHeadline" />
      </Style>

In my MainPage, I just gave below to load my font

<TextBlock Text="Do not display Font load purpose only"
                   Width="1"
                   Height="1"
                   Style="{StaticResource RadWindowTitleTextStyle}"
                   Foreground="Transparent" />

Below is my point of interest in one of my ChildWindow popup styles resource dictionary called RadWindowStyles.xaml

<TextBlock Text="{TemplateBinding Title}"
           Style="{StaticResource RadWindowTitleTextStyle}" />