15.8. Offline Applications

Probably the best feature of Silverlight 3.0 is the ability it offers to run your applications offline. Offline Silverlight applications run with the same permissions as their web counterparts, so they do not require additional permissions to install. Offline applications also work on both PC and Mac platforms, providing a very easy way to create cross-platform .NET applications.

15.8.1. Creating an Offline Application

Enabling your Silverlight applications to run offline is very easy and involves making a simple change to the AppManifest file. Try it now:

  1. Create a new Silverlight application called Chapter15.Offline.

  2. Add some content (e.g., an image).

  3. Open the project properties (see Figure 15-22).

    Figure 15.22. Enabling offline application in project properties
  4. Select the "Enable running application outside of browser" box.

  5. Click the Out-of-Browser Settings button, and note that you can set properties such as images, window size, and application title.

  6. Press F5 to run your Silverlight project, and then right-click the Silverlight app. The Silverlight menu will open.

  7. Select the "Install Chapter15.Offline Application onto this computer" option (see Figure 15-23).

    Figure 15.23. Installing a Silverlight application onto the computer
  8. Silverlight will then ask you to confirm where you want to place shortcuts to your application: on the Start menu and/or on the desktop (see Figure 15-24).

    Figure 15.24. Offline Silverlight application
  9. Select both the Start menu and desktop.

  10. Close the browser.

  11. Now click one of the shortcuts that has been created, and your application will load, running offline (see Figure 15-25).

    Figure 15.25. Running a Silverlight application offline

15.8.2. Uninstalling Offline Silverlight Applications

If you want to uninstall an offline Silverlight application, simply right-click the window when it is running locally, and select the "Remove this application" option.

15.8.3. Detaching Manually

You probably don't want to explain these steps to end users, so the Silverlight API contains an Application.Current.Install() method that performs the same functionality. Application.Current.Install() method returns a Boolean value indicating whether the detachment was possible.

15.8.4. Retrieving Attachment State

To query whether your application is running online in a browser or detached, use the Application.Current.IsRunningOutOfBrowser() method.

15.8.5. Detecting Connection Status

Now that you have the ability to run applications offline, it is very useful to be able to determine whether the user is connected to the Internet. This can be accomplished through the GetIsNetworkAvailable() method that returns true if the user is connected:

System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()

If the user has chosen to work in offline mode, this method will still return true.


You also have the ability to monitor network address changes through the NetworkAddressChanged event:

System.Net.NetworkInformation.NetworkChange.NetworkAddressChanged()

15.8.6. Autoupdate

When offline applications are run, Silverlight automatically checks to see whether a later version is available. If it is, it is downloaded.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.164.82