The partial class includes three things:
??? Fields for all the controls in your window.
??? Code that loads the BAML from the assembly, thereby creating the tree of objects. This
happens when the constructor calls InitializeComponent().
??? Code that assigns the appropriate control object to each field and connects all the
event handlers. This happens in a method named Connect(), which the BAML parser
calls every time it finds a named object.
The partial class does not include code to instantiate and initialize your controls
because that task is performed by the WPF engine when the BAML is processed by the
Application.LoadComponent() method.
nNote As part of the XAML compilation process, the XAML compiler needs to create a partial class. This
is only possible if the language you??™re using supports the .NET Code DOM model. C# and VB support Code
DOM, but if you??™re using a third-party language you??™ll need to make sure this support exists before you can
create compiled XAML applications.
Here??™s the (slightly abbreviated) Window1.g.vb file from the eight ball example shown in
Figure 2-1:
Partial Public Class Window1
Inherits System.Windows.Window
Implements System.Windows.Markup.IComponentConnector
' The control fields.
Friend WithEvents txtQuestion As System.Windows.Controls.TextBox
Friend WithEvents cmdAnswer As System.
Pages:
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165