Prev | Current Page 173 | Next

Matthew MacDonald

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


Now you can use that collection elsewhere in your code to loop over all the documents
and use public members. In this case, the Document class includes a custom SetContent()
method that updates its display:
Private Sub cmdUpdate_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
Dim app As ApplicationCore = CType(Application.Current, ApplicationCore)
For Each doc As Document In app.Documents
doc.SetContent("Refreshed at " & DateTime.Now.ToLongTimeString() & ".")
Next
End Sub
Figure 3-1 demonstrates this application. The actual end result isn??™t terribly impressive,
but the interaction is worth noting??”it demonstrates a safe, disciplined way for your windows
to interact through a custom application class. It??™s superior to using the Windows property,
because it??™s strongly typed, and it holds only Document windows (not a collection of all the
windows in your application). It also gives you the ability to categorize the windows in
another, more useful way??”for example, in a Dictionary collection with a key name for easy
lookup. In a document-based application, you might choose to index windows in a collection
by file name.
CHAPTER 3 n THE APPLICATION 68
Figure 3-1. Allowing windows to interact
nNote When interacting between windows, don??™t forget your object-oriented smarts??”always use a layer
of custom methods, properties, and events that you??™ve added to the window classes.


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