This article is compatible with the latest version of Silverlight.
Introduction
A cool new feature in Silverlight is the ability to run Silverlight applications out of the browser which resembles a desktop application. Only a few configuration steps are needed to enable your application to run offline.
See also:
Tip: Detecting Network Change in Silverllight 3 Application
Overview
To enable this feature you only need to open the AppManifest.xml file which can be found in the Properties folder and add
some settings as follows:
<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment" |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
EntryPointAssembly="TaskList" |
EntryPointType="TaskList.App"> |
<Deployment.Parts> |
</Deployment.Parts> |
<Deployment.OutOfBrowserSettings> |
<OutOfBrowserSettings |
ShortName="Task List"> |
<OutOfBrowserSettings.WindowSettings> |
<WindowSettings Title="Offline Task List" /> |
</OutOfBrowserSettings.WindowSettings> |
<OutOfBrowserSettings.Blurb> |
Allows saving your tasks offline |
</OutOfBrowserSettings.Blurb> |
</OutOfBrowserSettings> |
</Deployment.OutOfBrowserSettings> |
</Deployment> |
|
Provided that your application is called TaskList you must add two attributes to the Deployment element:
- EntryPointAssembly="TaskList"
- EntryPointType="TaskList.App"
You must also add the OutOfBrowserSettings section with the following settings:
- ShortName - the name of the application displayed on the desktop or the start menu.
- Title - the title displayed in the title bar of the window which runs the application.
- Blurb - this is seen in the "Comments" section of the file.
You are done. When you run your application in the browser you can notice the following context menu:
Note that if your application is not configured for offline use the "Install ... onto this computer..." is disabled and since we've configured it we can click it and the following dialog appears:
You have the option to choose where to put shortcuts to your application. By clicking "OK" you are ready and your Silverlight application is added as a standalone application.
Removing the application is as easy as adding it. When your application is saved for offline use the context menu looks as follows:
Clicking "Remove this application" and confirming removes the application from wherever it is added and also removes the shortcuts.
You also have the option to put your own icons which will be used by your application as a desktop icon, icon in the start menu, etc. You just need to create 4 png files with sizes 16x16, 32x32, 48x48 and 128x128. Include them in your project and set their Build Action to Content. It's easy, just right click on the image in the Solution Explorer and go to Properties. After that you must specify paths to the icons in the OutOfBrowserSettings section as follows:
<OutOfBrowserSettings.Icons> |
<Icon Size="16,16">Images/sls16.png</Icon> |
<Icon Size="32,32">Images/sls32.png</Icon> |
<Icon Size="48,48">Images/sls64.png</Icon> |
<Icon Size="128,128">Images/sls128.png</Icon> |
</OutOfBrowserSettings.Icons> |
That's all. You have your custom icons.
Now the whole AppManifest.xml file looks like:
<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment" |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
EntryPointAssembly="TaskList" |
EntryPointType="TaskList.App"> |
<Deployment.Parts> |
</Deployment.Parts> |
<Deployment.OutOfBrowserSettings> |
<OutOfBrowserSettings |
ShortName="Task List"> |
<OutOfBrowserSettings.WindowSettings> |
<WindowSettings Title="Offline Task List" /> |
</OutOfBrowserSettings.WindowSettings> |
<OutOfBrowserSettings.Blurb> |
Allows saving your tasks offline |
</OutOfBrowserSettings.Blurb> |
<OutOfBrowserSettings.Icons> |
<Icon Size="16,16">Images/sls16.png</Icon> |
<Icon Size="32,32">Images/sls32.png</Icon> |
<Icon Size="48,48">Images/sls64.png</Icon> |
<Icon Size="128,128">Images/sls128.png</Icon> |
</OutOfBrowserSettings.Icons> |
</OutOfBrowserSettings> |
</Deployment.OutOfBrowserSettings> |
</Deployment> |
The application updates automatically whenever you release a new version on the server. When you start the offline version or it detects that the network is present it checks for a new version, downloads it and updates itself. Whenever you start it again you will be using the updated version.
Demo
As an example I created the following demo:
This is a simple tasks list. You can add or delete tasks. The tasks are saved on the server and the application is using WCF Service to connect to the server. Nothing special. But if you save the application for offline use you can use it even if you don't have internet connection. I'm using the
isolated storage to keep copy of the data on the client and the application is working with the local copy when there is no connection. It synchronizes automatically whenever the connection comes back.
Download Source
Conclusion
This article describes the steps you need to make in order to allow the users to make your Silverlight application act like a Desktop application on their computers. Any comments are welcome.