Hosting the Silverlight application in the custom control

To host the Silverlight application in your control, you must create object element in the CoverFlow.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 data="data:application/x-silverlight-2," type="application/x-silverlight-2"
        width="100%" height="100%">
        <param name="source" value='<%= ResolveUrl("~/ClientBin/CoverFlowSilverlight.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" />
        <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50401.0" style="text-decoration: none">
            <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight"
                style="border-style: none" />
        </a>
    </object>
</div>

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.

Next steps

+1-888-365-2779
sales@sitefinity.com

Related topics:

Feedback

How useful is this article?

Tell us more

Submit
Your message was successfully sent.

We appreciate your feedback.

Your message could not be sent.

OK