A typical desktop WPF application displays its controls in Window objects. To create this type of application, select the File menu’s New Project command to display the New Project dialog box. On the Visual Basic ⇒ Windows tab, select WPF Application, enter a project name, and click OK.

The new application begins with a single Window class named Window1. Open the Solution Explorer and double-click the Window1.xaml entry to edit the Window’s controls. Double-click the Window1.xaml.vb entry to edit the Visual Basic code behind the Window.

The code behind a Window is called its code-behind. It’s not a very imaginative term, but it’s easy to remember.

To add other Window classes, open the Project menu and select Add Window. Enter a name for the class and click OK.

To display a window in code, create a variable that refers to a new instance of the window. Call its Show method to display the window non-modally, or call its ShowDialog method to display the window modally. The following code creates a new window of type Window2 and displays it modally:

Dim win2 As New Window2()

Although several similarities exist between the way a program uses a Window and the way it uses a Form, there are many significant differences.

For example, both classes have a DialogResult property that indicates how the user closed the form. Both classes’ ShowDialog methods return this result, so the code can easily determine the form’s DialogResult value. ...

Get Visual Basic 2012 Programmer's Reference now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.