DotNetNukeŽ Silverlight ToolBar
// Michael Washington
// Silverlight Tutorials
// http://www.adefwebserver.com/DotNetNukeHELP/Misc/Silverlight/
// Adapted from Justin-Josef Angel's
// "Silverlight Controls - The path to reusable XAML"
// http://blogs.microsoft.co.il/blogs/justinangel/archive/2007/08/14/Silverlight-Controls-_2D00_-The-path-to-reusable-XAML.aspx
// This JavaScript file defines the object "box"
box = function(ID, Parent, XLocation, XAMLFile, imgPicture, strWebsite)
{
this._ID = ID + "_";
this._parent = Parent;
this._XLocation = XLocation;
this._XAMLFile = XAMLFile;
this._imgPicture = imgPicture;
this._strWebsite = strWebsite;
this._host = this._parent.getHost();
this.Element;
// The first step is to retrive the XAML content for the "box"
this.StartXamlDownload();
}
box.prototype =
{
_findNameByXamlID : function(nameInXamlFile)
{
return this._parent.findName(this._getIdFor(nameInXamlFile));
},
_getIdFor : function(nameInXamlFile)
{
return this._ID + nameInXamlFile;
},
StartXamlDownload : function()
{
// A Silverlight "downloader" object is used to retrieve the "box.xaml" file that contains
// the XAML for the "box"
// A delegate is created that will call the "XamlDownloadCompleted" method when the
// download is completed
var xamlDownloader = this._host.createObject("downloader");
xamlDownloader.open("GET", this._XAMLFile);
xamlDownloader.addEventListener("completed", Silverlight.createDelegate(this, this.XamlDownloadCompleted));
xamlDownloader.send();
},
DownloadPicture : function()
{
// A Silverlight "downloader" object is used to retrieve the picture
// A delegate is created that will call the "XamlDownloadCompleted" method when the
// download is completed
var xamlDownloader = this._host.createObject("downloader");
xamlDownloader.open("GET", this._imgPicture);
xamlDownloader.addEventListener("completed", Silverlight.createDelegate(this, this.PictureDownloadCompleted));
xamlDownloader.send();
},
XamlDownloadCompleted : function(sender, eventArgs)
{
// The download of "box.xaml" has been completed
// "sender.ResponseText" contains the contents of "box.xaml"
var originalXaml = sender.ResponseText;
// In order to avoid name collisions, the name of each "box" object will be replaced
// with a name that begins with the ID that was passed in the object constructor
originalXaml = originalXaml.replace(/Name="/g, "Name=\"" + this._ID);
// The altered "box.xaml" is used to create a XAML object
var newElement = this._host.content.createFromXaml(originalXaml)
// Set Element to the XAML object so that it can be manipulated
this.Element = newElement;
// The "box" will now be added to the main Canvas
// The XML object is added to the element passed in the constructor
this._parent.children.add(this.Element);
// Now that the "box" has been added to the main Canvas
// the "BoxTitle" will be altered and the "box" position will be set
this._setControlReferences();
// Set the picture
// The Downloader wil be used because it allows us to know when the image is ready
// If we do not use the Downloader we may try to use an image that is not yet avalaible
this.DownloadPicture();
},
_setControlReferences : function()
{
this._box = this._findNameByXamlID("box");
this._box["Canvas.Left"] = this._XLocation;
this._box["Canvas.Top"] = 10;
this._box.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.handleMouseDown));
},
PictureDownloadCompleted : function(sender, eventArgs)
{
// The download of the picture has been completed
// setSource(sender, "") will set the source for the Thumbnail
// to value of "sender" which is the image
var originalXaml = sender.ResponseText;
var Thumbnail = this._findNameByXamlID("Thumbnail");
Thumbnail.setSource(sender, "");
//Also set the Reflection Image
var Thumbnail_Reflection = this._findNameByXamlID("Thumbnail_Reflection");
Thumbnail_Reflection.setSource(sender, "");
},
handleMouseDown: function(sender, eventArgs)
{
// Navigate to the website
window.location.href = this._strWebsite;
}
}