Silverlight Display Web Part

Home » SharePoint Development » Silverlight Display Web Part

Silverlight Display Web Part

Posted on

I’ll be the first to admit that I’m no Silverlight guru – all those sliding images and reflecting chrome are a bit fancy for my simple country-boy tastes.  But I was floored when one of our graphic artists brought me a few samples of some new marketing materials and showed me how he did it.  Allright, I give in, this stuff is really cool. 
 
So naturally I wanted to put his fancy Silverlight application on our web site.  Only problem is, there doesn’t seem to be an easy way to do that in SharePoint (WSS v3 in our case but the same applies to MOSS).  I would have thought that it would all be rendered out to a single object file (like .swf for Flash) and I could just throw an <object> tag into a content editor web part and be done with it.  Not so, apparently. The sample templates that ship with Visual Studio 2008 create the whole Silverlight project as a standard web site, with a bunch of images, a handful of javascript and a dll.  Now what am I supposed to do with that?
 
I did some quick searching on the web and all I could come up with was some rough web parts to show Silverlight web sites inside an iFrame.  I can do that with a page viewer web part, thank you very much, but that defeats the purpose.  Besides, I don’t like having unmanaged paths on my SharePoint servers; if you can’t build it into a web part,  server control, or user control then it has no business living on my SharePoint boxes (I know, it probably won’t hurt anything but it’s one of my pet peeves).
 
So by now I was annoyed by the whole thing and determined to find a fix.  The result is a generic Silverlight Display Web Part that I whipped up in about an hour (and most of that was spent figuring out the javascript and xaml pathing issues).  The web part is very simple – tell it where to find your basic Silverlight project (I only tested ones created with the sample VS08 project type), give it an ID (in case you want to have more than one on a page), and voila – pretty Silverlight pictures in SharePoint.  You can download it here.  It’s a .wsp file so your admins shouldn’t give you any grief about deploying it (just remember to activate it in your site collection after deployment). 
 
Instructions for deployment are in the ReadMe file.  The most important thing to remember is that the basic VS08 template stuffs everything into a single folder.  You’ll need to use virtual paths to get it working inside a SharePoint web application, so be sure to change any fixed references in the default.html.js and scene.xaml files to the correct relative paths (such as ‘/bin/TestProject/image1.png’).  And don’t forget to change the control id value in the default.html.js file if you change it in the web part so it will know where to find the right control on the page.
 
I’m sure there are probably already better solutions out there but I couldn’t find them in the first 100 or so search results and the new CodePlex search is about useless.  If you know of anything better please post a comment and enlighten the rest of us Silverlight noobs.  As always, if you have questions, issues or feature enhancements, post a comment and you will be heard (I may not do anything about it but at least I promise to read it).  Oh, and if you want the source code, just email me and I’ll zip it up and send it to ya.