Prev | Current Page 148 | Next

Matthew MacDonald

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


CHAPTER 2 n XAML 50
Imports System.Windows.Markup
Public Class Window1
Inherits Window
Private button1 As Button
Public Sub New()
InitializeComponent()
End Sub
Private Sub InitializeComponent()
' Configure the form.
Me.Width = Me.Height = 285
Me.Left = Me.Top = 100
Me.Title = "Code-Only Window"
' Create a container to hold a button.
Dim panel As New DockPanel()
' Create the button.
button1 = New Button()
button1.Content = "Please click me."
button1.Margin = New Thickness(30)
' Attach the event handler.
AddHandler button1.Click, AddressOf button1_Click
' Place the button in the panel.
Dim container As IAddChild = panel
container.AddChild(button1)
' Place the panel in the form.
container = Me
container.AddChild(panel)
End Sub
Private Sub button1_Click(ByVal sender As Object, _
ByVal e As RoutedEventArgs)
button1.Content = "Thank you."
End Sub
End Class
Conceptually, the Window1 class in this example is a lot like a form in a traditional
Windows Forms application. It derives from the base Window class and adds a private member
variable for every control. For clarity, this class performs its initialization work in a
dedicated InitializeComponent() method.
CHAPTER 2 n XAML 51
Figure 2-3. A single-button window
To get this application started, you can use a Main() method with code like this:
Public Class Program
Inherits Application
Public Shared Sub Main()
Dim app As New Program()
app.


Pages:
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160