Hello, all!
Well, everybody is talking about Silverlight these days, so I would like to put couple of cents here and share with you extremely simple techique how it could be useful to mojoLovers.
I will talk about Slide Show/Image Gallery only, but the same technique may be usefull in other cases also.
I googled the Web looking for nice and attractive Image Gallery for my project kaskad-dc.spb.ru (that is powered by mojoPortal of cause! ) and found Vertigo SlideShow control (live example, manual and download instructions) here: www.vertigo.com/SlideShow.aspx
Briefly speaking this is Open Source control for Silverlight 1.0 (pure JavaScript, that's amazing!) that was developed by commercial organisation with huge creativity and with the cutting edge quality. I was really imressed and I would like to thank them in public.
Since it is Open Source and since it is free I did following:
1. I put files Silverlight.js and SlideShow.js in /ClientScript folder of the site. (They both are provided with SlideShow release)
2. I followed simple 3-step Quick Start Guide to configure SlideShow control.
You may see the result here: kaskad-dc.spb.ru/gallery.aspx
If you love it, take a deep breath - I will jump 2 steps further and continue with some boring C# implementation details.
"Better is the worst enemy of good", so after first couple hours of joy and excitement I have realised, that publishing of real images in real site is a little bit boring task. Since currently I am playing with Silverlight version 2, then after some googling I found Vertigo SlideShow2 control developed with C# specially for this newer version. New control is able to play video as well, so one can mix images with something more exciting.
It is Open Source and free also, so deployment steps were following:
1. I put file Vertigo.SlideShow.xap in /ClientBin folder of the site.
2. I followed 3-step configuration process which is even easier and more flexible for second version.
3. I realilsed, that Html Content feature of mojoPortal is more than enough to embed SlideShow2 control into web-page, because it is just <object> tag with some specific parameters.
Ta-daaa! You may see the result here: kaskad-dc.spb.ru/gallery.aspx
The most significant drawback of Silverlight 2 is it's "cross platform" "compatibility" with different OSes and browsers. I personally live with FireFox and Ubuntu, so I had to install Moonlight from the Mono project. But this is not enough! Full XAP support will be ready on September, 2009 only (the best wishes to the guys!)
I have decided to expand cross-platform-cross-browser abilities of SlideShow and mix them in single mojoPortal feature.
- Basically, if visitor uses Windows, I display SlideShow2 - if he loves Ms, he for sure will download and install Silverlight 2 and .NET framework 3.5.
- All other guys will see SlideShow1 in pure JavaScript.
I had not much time to create some kind of redistributable package, but I want to share my SlideShow.ascx and SlideShow.ascx.cs files right here. (wow, it is like "feature request": "Joe, please, implement file attachments to our Forum feature! Thank you!" ) This control may be in a minute registered on working portal by hands in usual way.
Best Regards,
Anton Kytmanov
kyta.spb.ru
SlideShow.ascx:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SlideShow.ascx.cs" Inherits="Vertigo.SlideShow.SlideShow" %>
SlideShow.ascx.cs:
using System;
using System.Collections;
using System.Configuration;
using System.Globalization;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using mojoPortal.Web;
namespace Vertigo.SlideShow {
public partial class SlideShow : SiteModuleControl {
#region Constants
private const string silverlight2_ObjectFormat = @"
<object type=""application/x-silverlight-2""
data=""data:application/x-silverlight-2,""
width=""{0}"" height=""{1}"">
<param name=""background"" value=""{2}"" />
<param name=""source"" value=""{3}"" />
<param name=""initParams"" value=""{4}"" />
<a href=""http://go.microsoft.com/fwlink/?LinkID=124807"" style=""text-decoration: none;""><img src=""http://go.microsoft.com/fwlink/?LinkId=108181"" style=""border-style: none;"" alt=""Get Microsoft Silverlight"" /></a>
</object>
";
private const string silverlight1_Object = @"
<script type=""text/javascript"">
new SlideShow.Control(new SlideShow.XmlConfigProvider());
</script>
";
#endregion Constants
private uint width = 530;
private uint height = 400;
private string bgColor = "white";
private string pathToXAP = @"/ClientBin/Vertigo.SlideShow.xap";
private string initParams = @"ConfigurationProvider=LightTheme,DataProvider=XmlDataProvider;Path=/Data/Sites/1/FolderGalleries/Data2.xml";
private string controlPresentationInHtml = "";
public SlideShow() : base()
{
controlPresentationInHtml = string.Format(CultureInfo.InvariantCulture,
silverlight2_ObjectFormat,
width, height, bgColor, pathToXAP, initParams);
}
protected void Page_Load (object sender, EventArgs e) {
// If Windows...
if (Request.Browser.Platform.ToUpperInvariant().StartsWith("WIN")) {
// Unknown;
// Win95; Win98; Windows NT 5.0 (Windows 2000); Windows NT 5.1 (Windows XP); WinNT (all other versions of Windows NT); Win16; WinCE
// Mac68K; MacPPC
// UNIX
// WebTV
controlPresentationInHtml = string.Format(CultureInfo.InvariantCulture,
silverlight2_ObjectFormat,
width, height, bgColor, pathToXAP, initParams);
return;
}
// Prepare JavaScript
controlPresentationInHtml = silverlight1_Object;
string myScript = "\n<script type=\"text/javascript\" src=\"" + ResolveUrl ("/ClientScript/Silverlight.js") + "\"></script>";
if (!Page.ClientScript.IsClientScriptBlockRegistered ("Silverlight")) {
Page.ClientScript.RegisterClientScriptBlock (typeof (SlideShow), "Silverlight", myScript, false);
}
myScript = "\n<script type=\"text/javascript\" src=\"" + ResolveUrl ("/ClientScript/SlideShow.js") + "\"></script>";
if (!Page.ClientScript.IsClientScriptBlockRegistered ("VertigoSlideShow")) {
Page.ClientScript.RegisterClientScriptBlock (typeof (SlideShow), "VertigoSlideShow", myScript, false);
}
}
protected override void Render (HtmlTextWriter writer) {
writer.Write (controlPresentationInHtml);
}
}
}