Wednesday, April 8, 2009

Silverlight 3 Fonts Loading or Not

Ariel (http://www.facingblend.com/) built this cool Simon says UI in Xaml (remember the electronic version that first came out I think in the early 80's) and asked me to add some brains for fun :) the game logic is pretty simple enough by C# standards. Ariel even got this cool electronic LED looking font. So I got it all working and I noticed that once the score got above 2 the cool font started being not so cool. I thought this might be a messed up or incomplete font or something bizarre but Ariel mentioned something about loading only the parts of the font needed on render or only the part of the font need is compiled into the xap... ??? hmmm... I could see a hack coming on.

I put this bit of xaml in the simon control:

<TextBlock Height="56" Width="60"
FontFamily="./Fonts/Fonts.zip#Digital Readout" Text="0 1 2 3 4 5 6 7 8 9"
Visibility="Collapsed" /$gt;

I compiled Simon and played a few turns until it got a bove 2 and poof my score board was working with all the font elements I need and still w/o the characters I'm not using. Its a hack but works great.