Silverlight中如何为浏览器外应用程序实现脱机支持(4)

2012-04-09
浏览
导读:C# using System; using System.Net.NetworkInformation; using System.Windows; using System.Windows.Controls; namespace OutOfBrowser { public partial class MainPage : UserControl { Application app = App

C#

using System;
using System.Net.NetworkInformation;
using System.Windows;
using System.Windows.Controls;
namespace OutOfBrowser
{
public partial class MainPage : UserControl
{
Application app = Application.Current;
public MainPage()
{
InitializeComponent();
LayoutRoot.DataContext = Deployment.Current.OutOfBrowserSettings;
UpdateUI ();
app.CheckAndDownloadUpdateCompleted +=
App_CheckAndDownloadUpdateCompleted;
app.InstallStateChanged += (s,e) => UpdateUI();
NetworkChange.NetworkAddressChanged +=
(s, e) => UpdateNetworkIndicator();
}
private void UpdateUI()
{
UpdateNetworkIndicator();
installButton.Visibility =
app.InstallState == InstallState.NotInstalled ?
Visibility.Visible : Visibility.Collapsed;
updateButton.Visibility =
app.IsRunningOutOfBrowser ?
Visibility.Visible : Visibility.Collapsed;
isRunningOutOfBrowserTextBlock.Text =
app.IsRunningOutOfBrowser.ToString();
installStateTextBlock.Text = app.InstallState.ToString();
}
private void UpdateNetworkIndicator()
{
networkIndicator.Visibility =
app.IsRunningOutOfBrowser ?
Visibility.Visible : Visibility.Collapsed;
bool online = NetworkInterface.GetIsNetworkAvailable ();
networkIndicator.Text = online ?
"ONLINE" : "OFFLINE";
updateButton.Visibility = online ?
Visibility.Visible : Visibility.Collapsed;
}
private void installButton_Click(object sender, RoutedEventArgs e)
{
try
{
app.Install();
}
catch (InvalidOperationException)
{
MessageBox.Show("The application is already installed.");
}
}
private void updateButton_Click(object sender, RoutedEventArgs e)
{
app.CheckAndDownloadUpdateAsync();
}
private void App_CheckAndDownloadUpdateCompleted(object sender,
CheckAndDownloadUpdateCompletedEventArgs e)
{
if (e.UpdateAvailable)
{
MessageBox.Show("An application update has been downloaded. " +
"Restart the application to run the new version.");
}
else if (e.Error != null &&
e.Error is PlatformNotSupportedException)
{
MessageBox.Show("An application update is available, " +
"but it requires a new version of Silverlight. " +
"Visit the application home page to upgrade.");
}
else
{
MessageBox.Show("There is no update available.");
}
}
}
}

other

<OutOfBrowserSettings ShortName="Out-of-Browser Demo"
  EnableGPUAcceleration="False" ShowInstallMenuItem="True">
  <OutOfBrowserSettings.Blurb>
   This application demonstrates Silverlight's out-of-browser support.
  </OutOfBrowserSettings.Blurb>
  <OutOfBrowserSettings.WindowSettings>
   <WindowSettings Title="Silverlight Out-of-Browser Demonstration"
    Height="250" Width="500" />
  </OutOfBrowserSettings.WindowSettings>
  <OutOfBrowserSettings.Icons />
</OutOfBrowserSettings>

Silverlight编程模型、XAML和HTML DOM

Silverlight对象树

Silverlight中如何为浏览器外应用程序实现

Silverlight中如何为浏览器外支持配置应用

使用LINQ和ADO.NET创建Silverlight程序