WPF Through an Example: Introduction - Creating a WPF Project
(Page 2 of 4 )
Let's first take a look at creating a WPF project. Open up Visual Studio 2008 and open the New Project dialog. There are two main WPF project templates: WPF Application and WPF Browser Application. The WPF Application template is used for standard desktop applications, and it's what we'll be using here. The WPF Browser Application is used for browser-hosted applications. Creating a browser application isn't much different from creating a desktop application, but we won't be going that route. If you like, you can play around with the WPF Browser Application template on your own.
Go ahead and use the WPF Application template to create a C# project named WpfToDo. When the project is created and loaded, you should immediately see a split-view in the workspace. On the top will be a visual representation of the application's default window, and on the bottom will be the corresponding XAML. The visual part will probably be bigger, but you may want to click the Swap Panes button in order to enlarge the XAML view.
For now, though, leave the workspace area alone and take a look at the Solution Explorer. You should see two files, App.xaml and Window1.xaml. As the extensions give away, these contain the application's XAML. If you expand the two files, you should see something like this:

Under the XAML files are the code-behind files, whose names are created simply by appending “.cs” to the XAML file names. As you've probably noticed, the structure is similar to the structure of an ASP.NET application, so the structure isn't something radically new that you have to get used to. The -.xaml files of WPF are analogous to the -.aspx files of ASP.NET, and the code-behind files simply tack on the appropriate language extension.
The App files aren't very important to us right now. They deal with the application as a whole. For example, if we had a resource that we needed to share across the entire application, then we'd probably deal with that in the App files. But we don't. The only thing worth mentioning right now is one attribute in App.xaml:
<Application x:Class="WpfToDo.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Window1.xaml">
The attribute in bold specifies what the starting window is. In this case, it's Window1.xaml. With that, turn your attention to the Window1 files. Window1 is going to be the main window for our application.
Next: Creating the basic UI with XAML >>
More Windows Scripting Articles
More By Peyton McCullough