Every time a file
CHAPTER 3 n THE APPLICATION 71
name is passed to SingleInstanceApplicationWrapper through the command line,
SingleInstanceApplicationWrapper calls WpfApp.ShowDocument().
Here??™s the code for the WpfApp class:
Public Class WpfApp
Inherits System.Windows.Application
Private Sub Application_Startup(ByVal sender As Object, _
ByVal e As System.Windows.StartupEventArgs) _
Handles Me.Startup
' Load the main window.
Dim list As New DocumentList()
Me.MainWindow = list
list.Show()
' Load the document that was specified as an argument.
If e.Args.Length > 0 Then
ShowDocument(e.Args(0))
End If
End Sub
Public Sub ShowDocument(ByVal filename As String)
Try
Dim doc As New Document()
Dim docRef As New DocumentReference(doc, filename)
doc.LoadFile(docRef)
doc.Owner = Me.MainWindow
doc.Show()
doc.Activate()
Catch
MessageBox.Show("Could not load document.")
End Try
End Sub
End Class
The only missing detail now (aside from the DocumentList and Document windows)
is the entry point for the application. Because the application needs to create the
SingleInstanceApplicationWrapper class before the App class, the application needs to start
with a traditional Main() method, rather than an Application.xaml file. Here??™s the code you
need:
Public Class Startup
Public Shared Sub Main(ByVal args As String())
Dim wrapper As New SingleInstanceApplicationWrapper()
wrapper.
Pages:
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190