Prev | Current Page 179 | Next

Matthew MacDonald

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

Run(args)
End Sub
End Class
CHAPTER 3 n THE APPLICATION 72
These three classes??”SingleInstanceApplicationWrapper, WpfApp, and Startup??”form the
basis for a single-instance WPF application. Using these bare bones, it??™s possible to create a
more sophisticated example. For example, the downloadable code for this chapter modifies
the WpfApp class so it maintains a list of open documents (as demonstrated earlier). Using
WPF data binding (a feature described in Chapter 16), the DocumentList window displays the
currently open documents. Figure 3-3 shows an example with three open documents.
Figure 3-3. A single-instance application with a central window
Finally, the SingleInstanceApplication example includes a FileRegistrationHelper class
that registers a file extension using the classes in the Microsoft.Win32 namespace:
Dim extension As String = ".testDoc"
Dim title As String = "SingleInstanceApplication"
Dim extensionDescription As String = "A Test Document"
FileRegistrationHelper.SetFileAssociation( _
extension, title & "." & extensionDescription)
This code needs to be executed only once. After the registration is in place, every time you
double-click a file with the extension .testDoc, the SingleInstanceApplication is started, and
CHAPTER 3 n THE APPLICATION 73
the file is passed as a command-line argument.


Pages:
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191