PETZOLD BOOK BLOG

Charles Petzold on writing books, reading books, and exercising the internal UTM


Recent Entries
< PreviousBrowse the ArchivesNext >
Subscribe to the RSS Feed

Experimental Embedding of Silverlight Apps in Blog Entries

December 15, 2009
New York, N.Y.

Commonly, blog entries that discuss Silverlight programming contain a link to a separate HTML or ASPX file that contains the actual Silverlight application. I want to start embedding Silverlight applications right in my blog entries. Since I wrote my own blogging software — it's a Windows Forms application called BlogHack and it's as sloppy as the name suggests — I figured it wouldn't be too difficult.

And it wasn't. BlogHack lets me enter and edit blog entries and maintains a database called blogbase.xml. When updating the blog, BlogHack generates several files that it copies to my web site: The blog.xml and rss.xml files are very similar; they share a number of tags and contain the most recent entries. A blogformat.xsl file formats the blog.xml file for viewing. The "archive" consists of a toc.html file ("toc" stands for "table of contents") and an HTML file for each blog entry. Each month's worth of blog entries goes in a separate directory.

I recently altered BlogHack so that only the first paragraph of each blog entry was copied into blog.xml and rss.xml, so I knew I didn't have to worry about those. That reduced the problem to getting the Silverlight into the individual HTML files. In theory, it's only a matter of embedding an <object> tag, but I wanted to bring the JavaScript in as well for the Silverlight installation.

Whenever there's a blog entry with an embedded Silverlight application, the directory for that month of blog entries will contain the standard Silverlight.js file as well as a ClientBin directory containing all the Silverlight XAP files for that month.

And here we are. On the left is a little bitty Silverlight program that displays a ScrollBar and sends the value locally using the LocalMessageSender class. On the right is another tiny Silverlight program with a TextBlock and an event handler for the MessageReceived event of the LocalMessageReceiver class. Manipulate the ScrollBar and the TextBlock changes.


Comments:

Way Cool. It makes me want to learn Silverlight. On second thought, I'll just ask you to do these things for me.

Deirdre, Tue, 15 Dec 2009 14:56:37 -0500

There's an interesting side effect; if I open this page in two (or more) browsers at the same time, for example one IE8 and one FF 3.5.5, only the first one opened has its TextBlock updated with the scroll position. The TextBlock in the other browser(s) just says 100%; the scrollbars update the first browser's TextBlock.

Henry Skoglund, Tue, 15 Dec 2009 16:07:19 -0500

That's an issue with LocalMessageReceiver. There can't be multiple receivers registered with the same name. I should have tested for that case. — Charles

You are a star!!!

— Anthony, Wed, 16 Dec 2009 11:00:34 -0500

By the way where can I get your software and I don't see the ClientBin directory?

— Anthony, Wed, 16 Dec 2009 11:05:38 -0500

As is common, directories are not visible under HTTP. However, you can access the actual XAP files from the ClientBin directory using the URLs of those files:

I'm not sure what software you're referring to. I didn't post the SimpleScrollBar and SimpleTextBlock projects because they're fairly trivial. BlogHack is a personal program, not intended for public distribution, much like my laundry basket. — Charles

Ive read about the LocalMessageSender class, but I'm curious what it physically uses to communicate between the local sl apps? I'm guessing named pipes...

Setiri, Tue, 2 Feb 2010 21:58:48 -0500

I am one of those people who, despite considering themselves well versed in rather obscure parts of C++ standard, have eternal problems with HTML and Web programming in general. I always wanted to write my own blog engine (since the other ones are either too complicated and/or too Web-clumsy) using Silverlight and I see that it may be doable. Thanks for the heads up Charles!

Tonko, Tue, 8 Jun 2010 20:29:38 -0400


Recent Entries
< PreviousBrowse the ArchivesNext >
Subscribe to the RSS Feed

(c) Copyright Charles Petzold
www.charlespetzold.com