Enabling Out Of Browser in Your Silverlight App
For the next three days in the 31 Days of Silverlight, we’re going to cover some of the intricacies of getting a Silverlight application to run outside the user’s browser. This is a relatively simple change to your app, but it also introduces new challenges, like the need to detect which mode the user is in, and whether they have network connectivity or not. The next two articles will cover these topics specifically.
Today, we’re going to show you how to get out-of-browser working. So let’s get started.
To make this a little easier, I have created a sample project for you to start with. Inside, you’ll find a simple application that has a video player, and two images. The first image indicates whether there is network connectivity, and the other is to allow the user to “Install” the application to their machine.
But before we deal with any of that, we need to get our application “enabled” for the out of browser experience. By default, Silverlight 3 applications are not enabled.
1. Go to your Silverlight project properties
Opening the properties of your Silverlight project will give you the choice to “Enable running the application out of the browser, in addition to some new configuration choices. We’ll get to those in a second. Here’s what the screens look like:
2. Customize Your Settings
Once you’ve enabled Out of Browser for your Silverlight application, you get a new button to customize the settings for your installation. It includes things like titles, descriptions, and icons of different sizes for the shortcuts on your user’s machines. Here’s my completed Settings screen:
In case you’re curious, these settings are saved in a new XML file in your project. Look for OutOfBrowserSettings.xml in your Silverlight project’s Properties folder. Here’s what my settings file looks like:
<OutOfBrowserSettings ShortName="Big Bang Theory" EnableGPUAcceleration="False" ShowInstallMenuItem="True">
<OutOfBrowserSettings.Blurb>This application will play the theme song for the CBS television show Big Bang Theory in a video found on YouTube. You can also find the video here: http://www.youtube.com/watch?v=lhTSfOZUNLo</OutOfBrowserSettings.Blurb>
<WindowSettings Title="Big Bang Theory" Height="480" Width="640" />
3. Installing the Application
I’ve chosen not to embed my application below (you can launch it here), because it has audio, and I don’t want to have that playing while you’re reading this post. If you right click on the application, you should have a second choice: Installing the application. If you choose this, it will save your application down to the local sandbox on your machine, and also gives you some choices for where to install it. When you’re done, it will also launch the local version for you as well. At that point, you can close your browser, and the application still works.
Here is a screenshot of the installation dialog (with my custom icon):
And here is a screenshot of the application running in the out-of-browser window.
You can see that this is a pretty simple process to enable Out of Browser functionality for your Silverlight application. In the next two days, we’re going to work on adding to this application, detecting whether the user has installed it or not, and then whether or not they have a network connection. Yes, Virginia, your Silverlight application can now run in a disconnected mode. See you tomorrow!