iedotnetug silverlight class week 4
DESCRIPTION
Applications, resources, and deploymentTRANSCRIPT
Week 4 – Applications,
Resources, and Deployment
Jim LaVinejim.lavine @gmail.com
Agenda• Loading the application• XAP files• Binary resources• Xaml resources• Application class• Application extensions
Loading the Plugin• HTML <object> tag
– Compiled Silverlight content– Splash / download UI– Error Handling– Fallback content
Code Behind<object id=“slPlugin” width=“100%” height=“100%
type=“application/x-silverlight-2” data=“data:application/x-silverlight-2,”>
<param name=“source” value=“client/bin/SLContent.xap” />
<param name=“onerror” value=“onSilverlightError” />
<param name=“minRuntimeVersion” value=“4.0.50401 .0” /><param name=“autoUpgrade” value=“true” />
<a href=“http:go.microsoft.com/fwlink/?linkid=115261” style=“text-decoration: none;> <img src=“http:go.microsoft.com/fwlink/?linkid=108181” alt=“Get Microsoft Silverlight” style=“border-style: none”/></a>
</object>
Silverlight.js• Benefits– Silverlight.IsInstalled helper– Can choose content at runtime
• Disadvantages– More Complex– Extra file to download– Moving Target
Using Silverlight.js<script type="text/javascript" src="Silverlight.js"></script>…<div id=“slPLaceholder”></div>…<script type="text/javascript"> Silverlight.createObject( "ClientBin/SLObject.xap", document.getElementById("slPlaceholder"), "slControl", {width:"500" heigth:"500", version:'4.0'}, {onError: myErrorHandler} );</script>
XAP• Just a Zip
– Main DLL– Dependent DLLs– Resources– Mainfest
• Server config– Mime type for .xap:application/x-silverlight-app
AppManifest.Xaml<Deployment xmlns=http://schemas.microsoft.com/client/2007/deployment xmlns:x=“http://schemas.microsoft.com/winfx/2006/xaml”
EntryPointAssembly=“UriStyles” EntryPointType=“UriStyles.App” RuntimeVersion=“4.0.50401.0”>
<Deployment.Parts> <AssemplyPart xname=“UriStyles”
Source=“UriStyles.dll” />
<AssemplyPart xname=“Systems.Windows.Controls.Data” Source=“Systems.Windows.Controls.Data.dll” />
</Deployment.Parts>
</Deployment>
Application Library Caching• Package shared assemblies separately
– Exploit browser caching
<Deployment xmlns=http://schemas.microsoft.com/client/2007/deployment xmlns:x=“http://schemas.microsoft.com/winfx/2006/xaml”
EntryPointAssembly=“UriStyles” EntryPointType=“UriStyles.App” RuntimeVersion=“4.0.50401.0”><Deployment.Parts> <AssemplyPart xname=“UriStyles”
Source=“UriStyles.dll” /></Deployment.Parts><Deployment.ExternalParts> <ExtensionPart Source=“Systems.Windows.Controls.Data.zip” /></Deployment.ExternalParts>
</Deployment>
Resources: XAP vs ‘Loose’• Images, Media, etc. in Silverlight projects end
up in XAP:– Application is self contained– Availability guaranteed once application starts
• Can add to Web site instead– Faster startup– Easier to change
Resources and URIs
• Image ad MediaElement refer to resources
• Absolute ‘pack:’ URI not supported
URI Style LocationImg.jpg In Xap (falls back to site, relative
to .xap location)/Img.jpg In DLL as embedded resource
(alsofalls back to site)
/AssemblyName;component/Img.jpg In Xap (falls back to site, relative to .xap location)
http://example.com/app/Img.jpg Specified Location
Download UI• Define as Xaml
• Set SplashScreenSource <param>
• Optionally handle onSourceDownloadProgressChanged– V1 programming model - JavaScript