| Comments

UPDATE: The supported method for Silverlight 2 release is shown here: http://silverlight.net/learn/learnvideo.aspx?video=69800.  You basically have to make it an assembly resource.

Since the beginning of Silverlight you've been able to embed fonts within a Silverlight application.  The challenge in version 1.0 was that you essentially had to use a downloader and some SetFontSource methods on a TextBlock (for example) to do it.  I wrote about this a while back when using my own handwriting as a font within Silverlight. 

It looked something like this:

this.downloader = control.createObject("downloader");  
this.downloader.addEventListener("completed",
Silverlight.createDelegate(this, this.handleFontDownloaded));
this.downloader.open("GET", "timheuer.ttf");
this.downloader.send();

handleFontDownloaded: function(sender, eventArgs)
{
this.header.setFontSource(sender);
this.itemtext.setFontSource(sender);
this.header.fontFamily = "Tim Heuer Normal";
this.itemtext.fontFamily = "Tim Heuer Normal";
}

It isn't incredibly ideal for all situations.  It works, and in some scenarios might be valid and fine.

For most, I think we'll want an easier implementation and something that feels a bit more natural.  Well, in Silverlight 2, we now have it.  Let's take a look at the above sample and how we could do that for Silverlight 2:

<TextBlock x:Name="Header" FontFamily="timheuer.ttf#Tim Heuer Normal" /> <TextBlock x:Name="ItemText" FontFamily="timheuer.ttf#Tim Heuer Normal" />

Okay, so what is happening here?  What happened to the script?  There is none (obviously).  What is happening here is that Silverlight now does the lifting for you.  Let's break this down a bit more.

First, the FontFamily is set to "timheuer.ttf" in this example, which is my handwriting font in TrueType format.  This font is located next to the applications XAP file which is in ClientBin.  It could be located anywhere in the same application domain and you could use an absolute URL here as well.  For our purposes, we have a file on a web server.

When we set that in the FontFamily to a file, Silverlight essentially creates the downloader for us in an efficient manner.  The font file is requested based on the URI provided and downloaded via a GET request.  Once downloaded it parses out the second part (the "#") to look within that font file for the named font.  So essentially the format is:

<file>#<named-font>

where # is the delimiter in this format.  That's it, you are done.  No script needed.  If you choose to package several font assets within your application you can put them in a single archive file as well and the same syntax would apply:

<TextBlock x:Name="Header" FontFamily="timheuer.zip#Tim Heuer Normal" />

The same execution happens.  Silverlight gets the archive file and then looks at the font file contents in the archive to find the first named font to use.  The archive doesn't have to only have font files either...which is cool at times.

Hope this helps!

| Comments

For about a year now I've been using Amazon S3 services.  Mostly I'm using it for image storage for my blog and web site.  I decided to stop using Flickr for screenshot stuff and keep it to 'photographs' when I can.  I signed up for an S3 account and have been using it for screenshot type stuff since then.  If you don't know, S3 is a service that basically enables 'object' storage in the cloud.  An object can be anything really, but I'm treating it like a remote host for images.

The one thing Amazon doesn't provide themselves is a tool to manage your account...it is really an API only.  There are plenty out there that have implemented user interfaces around S3 services.  My two favorites are the S3 plugin for Firefox and BucketExplorerI use the Firefox one more than anything for uploading just because it was faster for what I needed.

UPDATE: While I still use the Firefox extension and always have it installed, I find myself using CloudBerry Explorer a LOT more.  It is the most full-featured (free) Amazon S3 tool I've seen and I love it.  They keep adding little subtle things to that make my process even easier!  Check it out today!

But the problem is that neither of the tools really incorporated *why* I was using S3 for me, which was primarily with my blog.  So a year ago I grabbed some of the sample code from the S3 developer site and whipped up a quick-and-dirty plugin for Windows Live Writer that I've been using.  I already had my Flickr4Writer plugin that I used for Flickr, but like I mentioned, I was using S3 for other image hosting now.  I was lazy though and only did a read version that inserted an image.  I was still relying on the other tools to upload, change permissions, etc. -- my workflow sucked.

Well as a part of The Code Trip, we set goals to release projects on CodePlex.  I decided to put this project out on CodePlex as far as I had it.  I immediately had a partner in Aaron Lerch.  He jumped in and within a day basically put in the remaining features that were lacking.

The result is the S3 Browser for Windows Live Writer project:

The initial 0.91 beta release is available on the project now.  Please give it a spin if you are a Live Writer and Amazon S3 user!

| Comments

When working with Silverlight 2, most will be working with managed code (c#, vb, etc.).  But likely people are working with Silverlight as an additive value to their web application, providing some enhanced user experience to an application.  there may be times where you will still need to call back into the hosting html context.  For then, you'll want to be familiar with two objects HtmlDocument and HtmlPage. 

Both of these objects provide access to the page context hosting your silverlight control.  If you need to seek things in the HTML DOM, you could use the HtmlDocument class.  For example, let's say I need to change the innerHTML property of some <div> element:

using System.Web.Browser;

HtmlDocument doc = HtmlPage.Document;
doc.GetElementById("mydiv").SetProperty("innerHTML", "<b>hello world</b>");

Also, i might want to interact with existing client-side functions, perhaps from client-side frameworks or other library utilities you might have developed on your own.  If I have a function on my page called "foo()" I would invoke it like this:

using System.Web.Browser;

HtmlPage.Window.CreateInstance("foo");

And if I had parameters in a function, like "foo2(theAlert)," I would invoke it like this:

using System.Web.Browser;

HtmlPage.Window.CreateInstance("foo2", new string[] { "tim heuer" });

This may not be the norm with your Silverlight project, but I hope this helps clear some things up!  I am including the "using" statements in my c# samples so you know where in the namespace the class library exists.

| Comments

John Lam just announced that the Dynamic Silverlight bits are now available.  What that does is enable you to write code targeting Silverlight in Ruby (IronRuby) or Python (IronPython).

The Dynamic Silverlight bits are implemented as Silverlight extensions which means that they will be downloaded on an as-needed basis.  The additional download is currently about 712KB download in size.  If you are interested in looking at running Ruby in the client on the desktop in addition to if you are running Ruby on the server, this might be of interest to you.  Check it out and some of John's tutorials as well as an update on IronRuby from his MIX08 session.

| Comments

We're off!  Just minutes ago The Code Trip left the Venetian hotel in Las Vegas en route to our first stop in Salt Lake City.  It's going to be a late night of coding and editing of some video.  Now that we've officially left, I'll share the actual pictures of our bus so you can be on the lookout for us:

The Code Trip

Tomorrow (late tonight) we roll in to Salt Lake for the combined .NET community user group meeting at the Franklin Covey building.  We're going to spend 2 hours talking about what we saw at MIX08.  We've got a special guest on board, Kelly White from the Portland area user experience group (PDXUX) who will be sharing his thoughts on Silverlight 2.  We'll show some of the Deep Zoom technology and some other great stuff!  Don't miss this if you are in the area.  See you soon!