Out of Browser und Silverlight 3 RTW

Die neue Funktion out of Browser erlaubt es Silverlight Anwendungen auch Offline zu betreiben. Das wird hier in einem Video gezeigt. Nur leider wird die RTW ( Release to web) erhebliche Änderungen mit sich bringen ( und das diese Woche noch!). Das Beispiel von der Silverlight Website kompiliert nicht mehr. Neben der Änderungen im Code wird nun statt im Appmanifest in einer neuen Datei OutofbrowserSettings.xml die Konfiguration vorgenommen.

<OutOfBrowserSettings ShortName="OutOfBrowser Application" EnableGPUAcceleration="True" ShowInstallMenuItem="True">
  <OutOfBrowserSettings.Blurb>OutOfBrowser Application on your desktop; at home, at work or on the go.</OutOfBrowserSettings.Blurb>
  <OutOfBrowserSettings.WindowSettings>
    <WindowSettings Title="OutOfBrowser Application" Height="400" Width="600" />
  </OutOfBrowserSettings.WindowSettings>
  <OutOfBrowserSettings.Icons>
    <Icon Size="16,16">Icons/task16.png</Icon>
    <Icon Size="32,32">Icons/task32.png</Icon>
    <Icon Size="48,48">Icons/task48.png</Icon>
    <Icon Size="128,128">Icons/task128.png</Icon>
  </OutOfBrowserSettings.Icons>
</OutOfBrowserSettings>

Das muss man aber nicht selbst tun. Über die Projekt Eigenschaften lässt sich das visuell konfigurieren.

outoffbrowser1

Eine derartige ausgestattet Silverlight Anwendungen lässt sich dann auch ins Windows Menü installieren.

Abschließend auch noch der geänderte Code damit die Demo Anwendung wieder läuft

Namespace

OutOfBrowser

Partial Public Class App

Inherits Application

Public Sub New()

AddHandler Me.Startup, AddressOf Application_Startup

AddHandler Me.Exit, AddressOf Application_Exit

AddHandler Me.UnhandledException, AddressOf Application_UnhandledException

AddHandler InstallStateChanged, AddressOf App_ExecutionStateChanged

InitializeComponent()

End Sub

Private Sub App_ExecutionStateChanged(ByVal sender As Object, ByVal e As EventArgs)

'Update B2 -> RTW

If App.Current.InstallState = Windows.InstallState.NotInstalled Then

MessageBox.Show(

"Restart the applicaiton to use the latest bits.")

End If

End Sub

Private Sub Application_Startup(ByVal sender As Object, ByVal e As StartupEventArgs)

Me.RootVisual = New MainPage()

End Sub

Private Sub Application_Exit(ByVal sender As Object, ByVal e As EventArgs)

End Sub

Private Sub Application_UnhandledException(ByVal sender As Object, ByVal e As ApplicationUnhandledExceptionEventArgs)

' If the app is running outside of the debugger then report the exception using

' the browser's exception mechanism. On IE this will display it a yellow alert

' icon in the status bar and Firefox will display a script error.

If (Not System.Diagnostics.Debugger.IsAttached) Then

' NOTE: This will allow the application to continue running after an exception has been thrown

' but not handled.

' For production applications this error handling should be replaced with something that will

' report the error to the website and stop the application.

e.Handled =

True

Deployment.Current.Dispatcher.BeginInvoke(

Function() AnonymousMethod1(e))

End If

End Sub

Private Function AnonymousMethod1(ByVal e As ApplicationUnhandledExceptionEventArgs) As Boolean

ReportErrorToDOM(e)

Return True

End Function

Private Sub ReportErrorToDOM(ByVal e As ApplicationUnhandledExceptionEventArgs)

Try

Dim errorMsg As String = e.ExceptionObject.Message + e.ExceptionObject.StackTrace

errorMsg = errorMsg.Replace(

""""c, "'"c).Replace(Constants.vbCrLf, Constants.vbLf)

System.Windows.Browser.HtmlPage.Window.Eval(

"throw new Error(""Unhandled Error in Silverlight Application " & errorMsg & """);")

Catch e1 As Exception

End Try

End Sub

End Class

End

Namespace

 

und in Mainpage

Namespace

OutOfBrowser

Partial Public Class MainPage

Inherits UserControl

Public Sub New()

InitializeComponent()

AddHandler Loaded, AddressOf MainPage_Loaded

AddHandler NetworkChange.NetworkAddressChanged, AddressOf NetworkChange_NetworkAddressChanged

End Sub

Private Sub MainPage_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)

If App.Current.IsRunningOutOfBrowser Then

InstanceMode.Text =

"Out of Browser"

Else

InstanceMode.Text =

"In Browser"

End If

End Sub

Private Sub NetworkChange_NetworkAddressChanged(ByVal sender As Object, ByVal e As EventArgs)

If NetworkInterface.GetIsNetworkAvailable() Then

ConnectivityIndicator.Text =

"Connected (online)"

ConnectivityIndicator.Foreground =

New SolidColorBrush(Colors.Green)

' check for updates from IsoStore

' push updates via web services to keep in sync

Else

ConnectivityIndicator.Text =

"Disconnected (offline)"

ConnectivityIndicator.Foreground =

New SolidColorBrush(Colors.Red)

' Save current data to IsoStore for offline use

End If

End Sub

Private Sub Button_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)

Dim allowed As Boolean = App.Current.Install()

If allowed Then

' do something here.

End If

End Sub

Private Sub Button_Click_1(ByVal sender As Object, ByVal e As RoutedEventArgs)

If NetworkInterface.GetIsNetworkAvailable() Then

' save online using web service

End If

' use IsolatedStorage because we're offline

End Sub

End Class

End

Namespace
Kommentare sind geschlossen