This event provides access to the command-line arguments. At this point, you??™ll
probably call a method in your WPF application class to show a new window but not
create another application object.
Here??™s the code for the custom class that??™s derived from WindowsFormsApplicationBase:
Public Class SingleInstanceApplicationWrapper
Inherits _
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase
Public Sub New()
' Enable single-instance mode.
Me.IsSingleInstance = True
End Sub
' Create the WPF application class.
Private app As WpfApp
Protected Overrides Function OnStartup(ByVal eventArgs As _
Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) As Boolean
app = New WpfApp()
app.Run()
Return False
End Function
' Direct multiple instances
Private Sub StartupNextInstance(ByVal sender As Object, ByVal e As _
Microsoft.VisualBasic.ApplicationServices.StartupNextInstanceEventArgs) _
Handles Me.StartupNextInstance
If e.CommandLine.Count > 0 Then
app.ShowDocument(e.CommandLine(0))
End If
End Sub
End Class
When the application starts, this class creates an instance of WpfApp, which is a custom
WPF application class (a class that derives from System.Windows.Application). The WpfApp
class includes some startup logic that shows a main window, along with a custom
ShowDocument() window that loads a document window for a given file.
Pages:
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189