Prev | Current Page 168 | Next

Matthew MacDonald

"Pro WPF with VB 2008: Windows Presentation Foundation with .NET 3.5"

Startup event. The arguments
are provided as an array of strings through the StartupEventArgs.Args property.
For example, imagine you want to load a document when its name is passed as a
command-line argument. In this case, it makes sense to read the command-line arguments
and perform the extra initialization you need. The following example implements this pattern
by responding to the Application.Startup event. It doesn??™t set the Application.StartupUri property
at any point??”instead the main window is instantiated using code.
Public Class Application
Private Sub Application_Startup(ByVal sender As Object, _
ByVal e As System.Windows.StartupEventArgs) Handles Me.Startup
' Create, but don't show the main window.
Dim win As New FileViewer()
If e.Args.Length > 0 Then
Dim file As String = e.Args(0)
If System.IO.File.Exists(file) Then
' Configure the main window.
win.LoadFile(file)
End If
Else
' (Perform alternate initialization here when
' no command-line arguments are supplied.)
End If
' This window will automatically be set as the Application.MainWindow.
win.Show()
End Sub
End Class
CHAPTER 3 n THE APPLICATION 65
This method initializes the main window, which is then shown when the
Application_Startup() method ends. This code assumes that the FileViewer class has a public
method (that you??™ve added) named LoadFile().


Pages:
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180