Silverlight 3: Out-of-Browser Applications

One of the most awaited and requested features before the release of Silverlight 3 Beta was the ability to run Silverlight applications out of the browser. To be clear, this is not completely out of the browser, since the browser chrome/host is still being used. However, the application can be run directly from the Start menu (or desktop), depending on what the user chose.

As a developer you can configure the application so that it can be installed for out of browser use. Next to out of browser, the application can also run offline but only if your code works in such a way that this is allowed. By that I mean you can work with IsolatedStorage to save some information local and use network detection to check for a network. If your application relies on services or files that are online you can disable working in offline mode (but still enable out of browser).

While this feature has been blogged about with Silverlight 3 there are some notable differences with the Silverlight 3 RTW. First it’s important to note the syntax for the application manifest has been changed.
Silverlight 3 Beta breaking changes: while the Beta version used “<Deployment.ApplicationIdentity>” the RTW version now uses <Deployment.OutOfBrowserSettings>

Sample:

 <Deployment.OutOfBrowserSettings>
<OutOfBrowserSettings ShortName="OobDemo Application" 
EnableGPUAcceleration="False" 
ShowInstallMenuItem="True">

…</OutOfBrowserSettings>
<Deployment.OutOfBrowserSettings>

The good news is Visual Studio is now giving you an editor to configure the out-of-browser settings.

Choose Silverlight project properties > Check “Enable running applications out of the browser” and click the “Out-of-Browser settings” button.

image

You might notice Visual Studio will create a separate “OutOfBrowserSettings.xml” file to store the settings. The contents of this file get concatenated with the AppManifest.xml file upon build, which is of course logical. If you need to change any of the settings manually (like the ShowInstallMenuItem), you will need to do this in the OutOfBrowserSettings.xml. Adding these out of browser settings in the App manifest file will result in duplicates.

image

When I now run this demo application and right-click I have the option to install the Silverlight application. This is the default behavior. You can also hide the display of the Install option in the right-click menu and control this programmatically, for example by adding a button “Install”.

image

image

When controlling the installation through your own interface you can use Application.Install to install the application out of browser, however this needs to be triggered by a user action. In the sample below I’m responding to a button click event:

 private void Install_Click(object sender, RoutedEventArgs e)
  {
    if (Application.Current.InstallState == 
                 InstallState.NotInstalled)
     {
       Application.Current.Install();
     }
 }

Looking forward to seeing applications make use of this feature, there is one out just as Silverlight 3 is released: it’s Sobees Silverlight Twitter client. Worth checking out (just right-click the app to install locally).