OdeToCode IC Logo

Tafiti and the Pain of Silverlight 1.0

Thursday, January 24, 2008


Tafiti is a search visualization application built with Silverlight 1.0 and the Windows Live APIs. The Tafiti code is hosted on CodePlex under the Microsoft Public License (MS-PL), as announced by Marc Mercuri last month.

What is amazing about Tafiti is the number of controls written in 3700 lines of JavaScript. Tafiti includes custom Button, Scrollbar, Hyperlink, TextEdit, StackPanel, FlowPanel, and Carousel controls. You can find the code inside the js folder of the Tafiti web project, inside a file by the name of controls.js.

Tafiti highlights some of the pain inherent in Silverlight 1.0 development, too. Most notably the pain felt from a total absence of any infrastructure needed to build these reusable controls. Tafiti provides this infrastructure for inself. For example, a generate UniqueNames method:

// Rewrite XAML to give the elements unique names.
// This is necessary because all names have global scope in WPF/E.
// Each %name% in the xaml string is replaced by %uniquename% and
// names["name"] is set to "uniquename".

Tafiti.generateUniqueNames = function (xaml, names) {
    xaml = xaml.replace(/%(\w+)%/g,
function (match, name) {
if (!names[name]) {
                                names[name] =
"Tafiti_" + Tafiti_uniqueID++;
return names[name];
return xaml;

If Silverlight 1.0 did not have such a short self-life, it would be worthwhile to genericze the Tafiti controls into a JavaScript library, but when Silverlight 2.0 hits the world this year I wouldn't be surprised to see those 3700 lines of code replaced with 370 lines of code. Silverlight 2.0 will take all this pain away...