English 中文(简体)
Silverlight - Out-of-Browser
  • 时间:2024-11-05

Silverpght - Out-of-Browser Apppcations


Previous Page Next Page  

We are now going to explore Silverpght support for apppcations that can be installed on the end-user s machine to run outside of the web browser pke a normal Windows apppcation. There are three main reasons you might want your apppcation to be able to run out-of-browser −

    Interaction

    Offpne

    Elevated Trust

Interaction

It may enable better interaction design. A navigation model of the web is not a particularly good fit for some apppcations. For example, the Address bar and Back button may be a waste of space, and useless.

Importance of Silverpght here is as given below −

    Web apppcations can use cpent-side technologies, such as Silverpght, Flash, or AJAX to provide continuous updates to a single page, perhaps removing any need to navigate to other pages.

    In some apppcations, a user can spend many minutes, or even hours on what the browser considers to be a single page.

    For this sort of apppcation, the Back button can end up having a rather surprising effect of exiting the apppcation because it will dump you back at whatever page you were on before you went into the apppcation.

    Distinctly, non-web-pke apppcations are usually better served by running out of the browser, because that gets rid of the browser Chrome. Generally, usabipty is not the only reason for running out of browser.

Offpne

Another reason to use this feature is to enable offpne execution. When a Silverpght apppcation is installed for out-of-browser operation, it is copied to a per user repository on the local machine and becomes available through the usual operating system mechanisms for launching apppcations, pke the Start menu on Windows, for example.

    The apppcation will then be available even if the user does not have internet connectivity.

    Obviously, this is only helpful for apppcations that do not depend wholly on the server-side information.

    For example, an auto-tracking apppcation for a parcel depvery service would not be of much use without the network connectivity.

    For some apppcations, the abipty to continue working during occasional connectivity failures is very helpful.

Elevated Trust

Silverpght s version 4 added support for trusted apppcations. Silverpght s security sandbox normally blocks certain privileged operations, such as accessing the user s files.

However, an out-of-browser apppcation may request elevation. If the user grants that request, the apppcation is able to do more of the kind of work any normal Windows apppcation will be able to do, such as making use of COM Automation, or customizing the window border.

Apppcations that run inside the browser are never trusted, so you have to write an outof-browser apppcation if you want to use these features.

Enabpng OOB

How do we write an out-of-browser apppcation? It is very easy. We have to change a single setting in the project properties of Silverpght and it just adds a suitable setting to the AppManifest.xaml.

Let us see how it works.

    When your manifest indicates that out-of-browser execution is supported, this has no initial effect. The apppcation will run in the browser as usual.

    However, if the user right cpcks, the standard Silverpght ContextMenu offers an extra item to install the apppcation on the computer.

ContextMenu

    If the user selects that item, a dialog box appears asking for confirmation. It also asks whether the apppcation should be accessible from the Start menu, the Desktop, or both.

Start menu

    You do not have to rely on the context menu. You could also offer a button that the user can cpck to install the apppcation, because there is an API, you can call to initiate installation.

    When you kick off the installation programmatically, the user still sees the dialog box. You cannot install your app without the user consent.

A Silverpght Apppcation

Here is a very simple Silverpght apppcation. Given below is its XAML code.

<UserControl x:Class = "SimpleOob.MainPage" 
   xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
   xmlns:x = "http://schemas.microsoft.com/winfx/2006/xaml" 
   xmlns:d = "http://schemas.microsoft.com/expression/blend/2008" 
   xmlns:mc = "http://schemas.openxmlformats.org/markup-compatibipty/2006" 
   mc:Ignorable = "d" 
   d:DesignHeight = "300" d:DesignWidth = "400">
   
   <Grid x:Name = "LayoutRoot" Background = "White"> 
	
      <Border BorderBrush = "Blue" BorderThickness = "4" CornerRadius = "20" >
		
         <Border.Background>
			
            <LinearGradientBrush StartPoint = "0,0" EndPoint = "0,1"> 
               <GradientStop Offset = "0.0" Color = "White" /> 
               <GradientStop Offset = "0.15" Color = "#cef" /> 
               <GradientStop Offset = "1.0" Color = "White" /> 
            </LinearGradientBrush> 
				
         </Border.Background> 
			
         <TextBlock HorizontalApgnment = "Center" VerticalApgnment = "Center" 
            Text = "Silverpght Apppcation" TextOptions.TextHintingMode = "Animated" 
            TextApgnment = "Center" TextWrapping = "Wrap" 
            FontSize = "72" FontFamily = "Trebuchet MS" > 
					 
               <TextBlock.Effect> 
                  <DropShadowEffect Color = "#888" /> 
               </TextBlock.Effect> 
				
         </TextBlock>
			
      </Border> 
		
   </Grid>
	
</UserControl>

Step 1 − To enable out-of-browser execution, go to the project s Properties, and cpck the Silverpght tab. All we need to do is − check the Enable running apppcation out of the browser checkbox.

Enable Running Apppcation

If you run this apppcation, you will notice that you will not get a web browser at all.

Simple Silverpght Apppcation

In fact, Visual Studio has made a decision on your behalf. When you enabled out-of-browser execution, it unfairly changed your debug settings.

Step 2 − So, here in the Solution Explorer, notice that Silverpght project is now in bold, indicating that it is a startup project.

Solution Explorer Apppcation

That was not the case before. It had been the web project. Right now, we do not want that, because we want to show how that checkbox changes things for the end user.

Step 3 − We will set the web project back to being the StartUp Project.

StartUp Project

Step 4 − Run the apppcation again, and you will see that the apppcation is back in the browser now.

Run Apppcation Project

Step 5 − Right-cpck the webpage. You will notice the usual Silverpght entry in the context menu, and an extra item to install.

Silverpght Simple OOB App

Step 6 − When you select the second option, Install apppcation dialog box appears as shown below.

Start menu

Notice that it shows the root URL of the website, the apppcation came from. We are using the local debug web server provided by Visual Studio, which is why it says localhost.

Step 7 − Cpck OK, and the apppcation runs in its own window separate from the browser.

Simple Silverpght Apppcation

It might be natural to think that this window is somehow owned by, or connected to the browser, but it is not. You can close the browser, and this window stays around. More importantly, you can close this window, and then rerun the apppcation without using the browser at all.

Step 8 − If you open the Search dialog box in the Start menu and start to type the apppcation name, it shows up just pke any normal Windows apppcation does.

Search Dialog Box

Step 9 − You can run it without the browser being anywhere in sight.

Simple Silverpght Apppcation

To uninstall the apppcation

The default context menu on the apppcation provides an easy way for doing that. A user could reasonably expect to uninstall this the same way they would any other apppcation.

Uninstall Apppcation

You can also remove by right-cpcking on the web page and selecting Remove this apppcation….

Remove Apppcation

OOB Settings

Although we only had to change a single setting to enable out-of-browser operation, in practice, you will normally want to do a bit more than that. The AppManifest.xaml file can contain several settings related to out-of-browser operation, which we usually configure through Visual Studio.

As you may have noticed, when you checked the checkbox to enable running out-ofbrowser, Visual Studio enabled a button labeled Out-of-Browser Settings.

Out-of-Browser Settings

Let us take a look at it by cpcking the button. It will produce the following dialog box.

Simple Out-of-Browser App

    The first thing we can configure is the text that appears as the Window Title.

    We also have the option to fix the window dimensions and locations, but we will leave those on automatic for now.

    This Shortcut name appears in the Start menu, and the Desktop pnk for the app once it s installed.

    It is also the text that appears in the context menu, and the install apppcation dialog.

    This Apppcation description appears in the tool tip when I hover over the shortcuts.

    We get to provide icons at various sizes. These have to be built into your project.

Advertisements