Prev | Current Page 172 | Next

Matthew MacDonald

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

In this example, each document window is represented by an instance of a
class named Document:
Public Class ApplicationCore
Private _documents As New List(Of Document)()
Public Property Documents() As List(Of Document)
Get
Return _documents
End Get
Set(ByVal value As List(Of Document))
_documents = value
End Set
End Property
End Class
CHAPTER 3 n THE APPLICATION 67
Notice that the application class has been named ApplicationCore instead of the standard
Application, which avoids confusion with the System.Windows.Application base class.
Now, when you create a new document, you simply need to remember to add it to the
Documents collection. Here??™s an event handler that responds to a button click and does the
deed:
Private Sub cmdCreate_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
Dim doc As New Document()
doc.Owner = Me
doc.Show()
CType(Application.Current, ApplicationCore).Documents.Add(doc)
End Sub
Alternatively, you could respond to an event like Window.Loaded in the Document class
to make sure the document object always registers itself in the Documents collection when it??™s
created.
nNote This code also sets the Window.Owner property so that all the document windows are displayed
???on top??? of the main window that creates them. You??™ll learn more about the Owner property when you consider
windows in detail in Chapter 8.


Pages:
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184