Implementing an Out-Of-Browser Application in Silverlight
In this tutorial I will show you how to implement an Out-Of-Browser application in Silverlight. I have included source code within this article if you want to actually try it out yourself. The source code was created using Silverlight 4.0 and Visual Studio 2010.
What is an Out-Of-Browser Silverlight Application?
It is commonly assumed that Silverlight applications are strictly meant to run on the browser, which is not true. A Silverlight application can be enabled to run Out-Of-Browser, and users can install the Silverlight application on the client, just like a desktop application.
- Using Visual Studio 2010, create a Silverlight application named OutOfBrowserDemo.
- Add the hosting web project as well.
- Right click on the Silverlight client project and select Properties.
- Tick the checkbox "Enable running application out of the browser" as shown in Fig 1.0
- Click on the Out-Of-Browser Settings button to set the below properties for the Out-Of-Browser application.
- Width & Height of the window
- Location of the Window
- Window Title
- Shortcut name
- Application Description
- Window icon
- To use GPU acceleration or not
- To show install menu or not
- Elevated trust required or not
Fig 1.1 Shows the Out-Of-Browser settings window
Hence, enabling a Silverlight application to run Out-Of-Browser is as simple as that.
Installing a Silverlight Application on the Client
In this section we will see how the user can install the Out-Of-Browser Silverlight application on their computer and also how a developer can customize the installation process.
Add the XAML code below to MainWindow.xaml.
What is the Install Option on the Browser?
In this section you will see how the user can install the application directly from their browser. First, run the Silverlight application host web page. Right click on the Silverlight section of the page and you will find the option "Install onto this computer" as shown in Fig 2.0. Clicking on it will install the application on the computer.
The only disadvantage with this approach is that the user won't be able to see that an Out-Of-Browser option is available until they right click on the browser.
Custom Implementation of an Out-Of-Browser Silverlight App
You can also control the installation process through code. Add the implementation for the button click event. Below is the source code:
public partial class MainPage : UserControl
private void SetView()
InstallButton.IsEnabled = false;
WelcomeNoteTextBox.Text = "This application is running in a Out-Of-Browser mode now";
InstallButton.IsEnabled = true;
WelcomeNoteTextBox.Text = "This is application is currently running on the browser";
private void InstallButton_Click(object sender, RoutedEventArgs e)
if (Application.Current.InstallState == InstallState.NotInstalled)
private void UnInstallButton_Click(object sender, RoutedEventArgs e)
Application.Current.InstallStateChanged += new EventHandler(Current_InstallStateChanged);
void Current_InstallStateChanged(object sender, EventArgs e)
Run the application and click on the installation button. You will be prompted with an installation dialog. Click on yes. Now you will see that the application is installed in the client and running in an Out-Of-Browser mode as shown in Fig 3.1.
Uninstalling the App
Eventually the thought of uninstalling the application comes into the picture. There are two options available:
- When you right click on the browser's Silverlight area now you will get an option saying "Remove this application". Use that to uninstall the application.
- Go to Add or Remove Programs in the Windows Control Panel and uninstall as you would do with other installed programs.
This article was intended to clearly explain how to implement an Out-Of-Browser application in Silverlight. Let me know through the commenting form below if you need any further clarifications on the topic, and if you would like me to cover any other particular topics about Silverlight, be sure to mention them as well.
Originally published on http://www.developer.com.