Tafiti and the Pain of Silverlight 1.0

Thursday, January 24, 2008

Tafiti

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...


Comments
Walter Smith Friday, January 25, 2008
It was indeed an adventure creating Tafiti...it does push the envelope for what's reasonable to do in SL 1.0. And bear in mind that it was started with early CTP builds of Silverlight that had even less infrastructure than 1.0 does! I am looking forward to 2.0, for sure.

But, that said, it isn't really any more unreasonable than what a lot of sites do in DHTML, which doesn't have a control framework either.

I agree, if 2.0 weren't on the way, no doubt we'd end up with the equivalent of Prototype or JQuery (perhaps derived from Tafiti) to take care of the heavy lifting.
Matt Casto Friday, January 25, 2008
The control framework in Silverlight 2.0 alone will make this all less complicated. Plus, who knows which of the layout controls will be included.

I just hope that Blend 2 will actually render controls, because currently the Blend 2 December Preview doesn't even render placeholders when you're looking at a XAML page with controls on it.
scott Friday, January 25, 2008
@Walter : Yes, what people have done with DHTML is pretty amazing.

@Matt: I'm 100% sure Blend will render controls. Just need to give it a bit more time ;)
Comments are now closed.
by K. Scott Allen K.Scott Allen
My Pluralsight Courses
The Podcast!