Here??™s one possible example, which simply
reads (and displays) the text in the file you??™ve identified:
Public Class FileViewer
...
Public Sub LoadFile(ByVal path As String)
Me.Content = File.ReadAllText(path)
Me.Title = path
End Sub
End Class
You can try an example of this technique with the sample code for this chapter.
nNote If you??™re a seasoned Windows Forms programmer, the code in the LoadFile() method looks a little
strange. It sets the Content property of the current Window, which determines what the window displays in
its client area. Interestingly enough, WPF windows are actually a type of content control (meaning they derive
from the ContentControl class). As a result, they can contain (and display) a single object. It??™s up to you
whether that object is a string, a control, or (more usefully) a panel that can host multiple controls. You??™ll
learn much more about the WPF content model in the following chapters.
Accessing the Current Application
You can get the current application instance from anywhere in your application using the
shared Application.Current property. This allows rudimentary interaction between windows,
because any window can get access the current Application object and through that obtain a
reference to the main window.
Dim main As Window = Application.
Pages:
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181