|
By now you've probably seen the MIX demos of creating out-of-browser Silverlight applications but I wanted to go through the process myself just to make sure that what was being demo'd actually worked. It's a good practice for many reasons, including finding potential bugs in the new CTPs as well as further cementing what I learned during the sessions.
An out-of-browser Silverlight 3 application is one that can be installed to the Start Menu and/or Desktop. These Silverlight applications can run with or without a network connection, they can detect changes to their network status, and they have increased storage quotas within Isolated Storage. If you've worked with ClickOnce, then the whole OOB experience should be very familiar... the difference is that the SL3 OOB experience is leaner, quicker, and most importantly, can be run by limited/restricted users!
So the first step in creating an OOB Silverlight application is creating a new SL3 application. The Out-of-Browser stuff is controlled almost entirely through the manifest properties in AppManifest.xml. The Deployment.ApplicationIdentity element is the element that enables "detaching" (separating the XAP from the browser), here's what my AppManifest.xml looks like:
<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
EntryPointAssembly="SilverlightOOB1"
EntryPointType="SilverlightOOB1.App">
<Deployment.Parts>
</Deployment.Parts>
<Deployment.ApplicationIdentity>
<ApplicationIdentity
ShortName="App of Awesome"
Title="Out-of-Browser Awesomeness">
<ApplicationIdentity.Blurb>This is the best application ever built. It will give you an awesome overdose!</ApplicationIdentity.Blurb>
<ApplicationIdentity.Icons>
<Icon Size="128x128">transformers128.jpg</Icon>
<Icon Size="64x64">transformers64.jpg</Icon>
<Icon Size="32x32">transformers32.jpg</Icon>
<Icon Size="16x16">transformers16.jpg</Icon>
</ApplicationIdentity.Icons>
</ApplicationIdentity>
</Deployment.ApplicationIdentity>
</Deployment>
Now when you run the application, you will be able to right-click the Silverlight surface and see the option to install the application on the desktop or the start menu (or both). It will also pick up your 128x128 icon and use that in the installation dialog (the current bits don't set the desktop/start menu icons though...). This is where it gets good: you can detect whether the application was launched attached (in-browser) or detached (OOB). This allows you to do things like hide a region of the application until the app has been installed. In my case, I will display the "Install Me" button if the app is not yet detached, and I'll display the "real" application GUI if it is detached. Here is my page startup code in the MainPage.xaml.cs file:
namespace SilverlightOOB1
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
if (Application.Current.ExecutionState == ExecutionStates.Detached)
{
LayoutRoot.Visibility = Visibility.Visible;
InstallPanel.Visibility = Visibility.Collapsed;
}
else
{
LayoutRoot.Visibility = Visibility.Collapsed;
InstallPanel.Visibility = Visibility.Visible;
}
}
private void mainButton_Click(object sender, RoutedEventArgs e)
{
if (Application.Current.ExecutionState != ExecutionStates.Detached)
{
Application.Current.Detach();
}
}
}
Here's a screenshot of the application launching before it has been detached:

When you click the Install button or when you right-click and choose install, you will be prompted to install the application. Here's what my install prompt looks like (note the custom logo/image supplied for the install prompt):

After I choose to install the Silverlight application, I get an icon on my desktop and an icon in my start menu. When you click either of these to launch the application (there is currently some weirdness with localhost-based SL3 apps but if you use a full-on website to deploy these it seems to work properly) you will get the application but this time it will detect that it is running in detached mode and display the "real" app GUI and hide the install button:

Even cooler is that in order to make it so that applications launch instantly, they check for updates asynchronously _after_ launch. Your application can then respond to the "ExecutionStateChanged" event and check to see if the app is now in the ExecutionStates.DetachedUpdatesAvailable state. This means that a new version of your app has been downloaded and is ready to go. You can use this event to inform your users that the app should be restarted to take advantage of the new goodies.
This is just the tip of the iceberg for the things that you can do with SL3 and I will be posting tons more walkthroughs and more in-depth coverage of some of the new features, so stay tuned!