The World’s Leading Microsoft .NET Magazine
   
 
The .NET Addict's Blog

My Top Tags

                                                           

My RSS Feeds








I heart FeedBurner

Latest Diggs - Programming

Computers Blogs - Blog Top Sites

Site Hits

Total: 4,907,932
since: 19 Jan 2005

Walkthrough: Creating an Out-of-Browser Application in Silverlight 3

posted Sat 21 Mar 09

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!

tags:          

links: digg this    del.icio.us    technorati    reddit

AddThis Social Bookmark Button




Tag Related Posts

What's New in Silverlight 3

Fri 20 Mar 09 2:38 P GMT-05

Live Mesh Tutorial 1 - Hello Live Mesh

Thu 06 Nov 08 2:33 P GMT-05

Smart, Deep Property Notifications in CLINQ v2.0

Tue 07 Oct 08 1:15 P GMT-05
tags:          

Microsoft's Lofty Direction

Sun 05 Oct 08 2:30 P GMT-05

MobileMe vs. Live Mesh Throwdown - Round 1

Wed 16 Jul 08 10:33 A GMT-05

One Framework to Rule them All

Mon 25 Feb 08 6:49 P GMT-05

My Silverlight Plugin has expired - WTF?!?

Thu 08 Nov 07 7:34 P GMT-05
tags:    

Silverlight 1.1 Alpha Refresh

Fri 10 Aug 07 2:09 P GMT-05
tags:    

My Appearance in the RIA Shootout on sys-con.tv

Tue 05 Jun 07 11:41 A GMT-05
tags:              

Silverlight and Astoria - First Impressions

Mon 04 Jun 07 1:40 A GMT-05
tags:    

I'm going to be on TV (sort of)

Sat 02 Jun 07 12:19 P GMT-05
tags:              

Silverlight Revisited

Sat 21 Apr 07 9:48 P GMT-05
tags:    

Will Silverlight be DOA?

Mon 16 Apr 07 8:02 P GMT-05

My Little Pony .NET Unleashed 2007

Fri 30 Mar 07 1:59 P GMT-05

Authorness

Thu 15 Mar 07 1:44 P GMT-05

Localizing a WPF Application

Tue 22 Aug 06 11:39 A GMT-05
tags:            

Is Windows Workflow Foundation Too Complex?

Fri 18 Aug 06 12:15 P GMT-05

Lambda Lambda Lambda

Sun 21 May 06 1:01 A GMT-05

The Adventures of LINQ (Not Zelda)

Fri 19 May 06 11:21 P GMT-05
tags: