That class derives from the class that??™s
named by the XML element. In other words, this example creates a new class named Window1,
which derives from the base Window class.
The Window1 class is generated automatically at compile time. But here??™s where things
get interesting. You can supply a piece of the Window1 class that will be merged into the automatically
generated portion. The piece you specify is the perfect container for your event
handling code.
CHAPTER 2 n XAML 29
nNote This magic happens through the VB feature known as partial classes. Partial classes allow you
to split a class into two or more separate pieces for development and fuse them together in the compiled
assembly. Partial classes can be used in a variety of code management scenarios, but they??™re most useful
in situations like these, where your code needs to be merged with a designer-generated file.
When you compile your application, the XAML that defines your user interface (such as
Window1.xaml) is translated into CLR type declaration that is merged with the logic in your
code-behind class file (such as Window1.xaml.vb) to form one single unit. Initially, the codebehind
class that Visual Studio creates is empty:
Class Window1
End Class
The InitializeComponent() Method
Currently, the Window1 class code doesn??™t include any code.
Pages:
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126