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.
Enabling your Silverlight applications to run offline is very easy and involves making a simple change to the AppManifest file. Try it now:
Create a new Silverlight application called Chapter15.Offline.
Add some content (e.g., an image).
Open the project properties (see Figure 15-22).
Select the "Enable running application outside of browser" box.
Press F5 to run your Silverlight project, and then right-click the Silverlight app. The Silverlight menu will open.
Select the "Install Chapter15.Offline Application onto this computer" option (see Figure 15-23).
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).
Select both the Start menu and desktop.
Close the browser.
Now click one of the shortcuts that has been created, and your application will load, running offline (see Figure 15-25).
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.
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.
To query whether your application is running online in a browser or detached, use the Application.Current.IsRunningOutOfBrowser() method.
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()
|
You also have the ability to monitor network address changes through the NetworkAddressChanged event:
System.Net.NetworkInformation.NetworkChange.NetworkAddressChanged()
When offline applications are run, Silverlight automatically checks to see whether a later version is available. If it is, it is downloaded.
18.226.164.82