Hosting the Silverlight application in the custom control
To host the Silverlight application in your control, you must create object element in the Book.ascx template file. The object element must point to the Silverlight application's .xap file. The .xap file is located in the ClientBin folder of the Sitefinity project. Following is the default code that is generated for the test pages of Silverlight applications:
<script type="text/javascript">
function onSilverlightError(sender, args) {
var appSource = "";
if (sender != null && sender != 0) {
appSource = sender.getHost().Source;
}
var errorType = args.ErrorType;
var iErrorCode = args.ErrorCode;
if (errorType == "ImageError" || errorType == "MediaError") {
return;
}
var errMsg = "Unhandled Error in Silverlight Application " + appSource + "\n";
errMsg += "Code: " + iErrorCode + " \n";
errMsg += "Category: " + errorType + " \n";
errMsg += "Message: " + args.ErrorMessage + " \n";
if (errorType == "ParserError") {
errMsg += "File: " + args.xamlFile + " \n";
errMsg += "Line: " + args.lineNumber + " \n";
errMsg += "Position: " + args.charPosition + " \n";
}
else if (errorType == "RuntimeError") {
if (args.lineNumber != 0) {
errMsg += "Line: " + args.lineNumber + " \n";
errMsg += "Position: " + args.charPosition + " \n";
}
errMsg += "MethodName: " + args.methodName + " \n";
}
throw new Error(errMsg);
}
</script>
<div id="silverlightControlHost" style="height: 400px; width: 100%">
<object id="silverlightBook" data="data:application/x-silverlight-2," type="application/x-silverlight-2"
width="100%" height="100%">
<param name="source" value='<%= ResolveUrl("~/ClientBin/BookSilverlight.xap") %>' />
<param name="onError" value="onSilverlightError" />
<param name="background" value="white" />
<param name="windowless" value="true" />
<param name="minRuntimeVersion" value="4.0.50401.0" />
<param name="autoUpgrade" value="true" />
style="border-style: none" />
</a>
</object>
</div>
Write down the ID of the object element, because you will need it later to access the Silverlight application via javascript.
The path to the .xap file is set via the source parameter of the object element.
NOTE: The path is not relative to the custom control, but to the Sitefinity application.