Click
button1.Content = "Thank you."
End Sub
End Class
Here, the InitializeComponent() method opens a FileStream on the Window1.xml file. It
then uses the Load() method of the XamlReader to convert the content in this file into a
DependencyObject, which is the base from which all WPF controls derive. This Dependency-
Object can be placed inside any type of container (for example, a Panel), but in this example
it??™s used as the content for the entire form.
nNote In this example, you??™re loading an element??”the DockPanel object??”from the XAML file. Alternatively,
you could load an entire XAML window (like the eight ball example). In this case, you would cast the
object returned by XamlReader.Load() to the Window type and then call its Show() or ShowDialog() method to
show it.
CHAPTER 2 n XAML 53
To manipulate the button, you need to find the corresponding control object in the
dynamically loaded content. The LogicalTreeHelper serves this purpose because it has the
ability to search an entire tree of control objects, digging down as many layers as necessary
until it finds the object with the name you??™ve specified. Although you could use explicit event
wireup (as in the previous example), this example attaches the event handler to the
Button.Click event using the Handles clause. As a result, the event handler will be connected
as soon as the button1 reference is set.
Pages:
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162