Prev | Current Page 115 | Next

Matthew MacDonald

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

However, there??™s one detail that??™s
completely hidden??”the default constructor. If you could see the constructor that Visual
Studio generates at compile time, it would look like this:
Public Sub New()
InitializeComponent()
End Sub
The InitializeComponent() method is another piece of automatically generated code that
doesn??™t appear in your class. It loads the BAML (the compiled XAML) from your assembly and
uses it to build your user interface. As it parses the BAML, it creates each control object, sets
its properties, and attaches any event handlers. (You??™ll see an example of the code that ends
up in the InitializeComponent() method later in this chapter in ???Code and Compiled XAML.???)
At this point, you??™re probably wondering why it??™s important to understand a detail that
Visual Studio hides from you completely. The reason becomes apparent if you create a custom
constructor for your window. In this case, you need to explicitly call the InitializeComponent()
method. If you don??™t, the window won??™t be initialized, and none of your controls will appear.
Naming Elements
There??™s one more detail to consider. In your code-behind class, you??™ll often want to manipulate
controls programmatically. For example, you might want to read or change properties or
attach and detach event handlers on the fly.


Pages:
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127