Bookmark and Share Share...    Subscribe to this feed Feed   About Christian Moser  

How to create a simple WPF application

In Visual Studio 2008

Open Visual Studio 2008 and choose "File", "New", "Project..." in the main menu. Choose "WPF Application" as project type.

Choose a folder for your project and give it a name. Then press "OK"

Visual Studio creates the project and automatically adds some files to the solution. A Window1.xaml and an App.xaml. The structure looks quite similar to WinForms, except that the Window1.designer.cs file is no longer code but it's now declared in XAML as Window1.xaml

Open the Window1.xaml file in the WPF designer and drag a Button and a TextBox from the toolbox to the Window

Select the Button and switch to the event view in the properties window (click on the little yellow lightning icon). Doubleclick on the "Click" event to create a method in the codebehind that is called, when the user clicks on the button.

Note: If you do not find a yellow lightning icon, you need to install the Service Pack 1 for VisualStudio on your machine. Alternatively you can doubleclick on the button in the designer to achieve the same result.

Visual Studio automatically creates a method in the code-behind file that gets called when the button is clicked.

private void button1_Click(object sender, RoutedEventArgs e)
    textBox1.Text = "Hello WPF!";

The textbox has automatically become assigned the name textBox1 by the WPF designer. Set text Text to "Hello WPF!" when the button gets clicked and we are done! Start the application by hit [F5] on your keyboard.

Isn't this cool!

Last modified: 2010-02-08 17:51:47
Copyright (c) by Christian Moser, 2011.

 Comments on this article

Show all comments
Faisal H...
Commented on 16.August 2011
The Great Website For WPF Learn Thanks Sir.
Commented on 22.August 2011
Begginer Examples Good
Commented on 23.August 2011
hi, i have already started doing the wpf application, but now im facing the problem that for different resolutions my application is not visible properly and some of part of the applications r getting cropped,,,, i have used the grid control to place the buttons, but for other resolutions the buttons r getting displaced, so pls any help me out how to resolve it,,,,,,,,,,
Commented on 25.August 2011
thanks ...
Its too esy to understand
Commented on 25.August 2011
Thanks !
Its too easy to understand .
Commented on 26.August 2011
Very useful. Thanks
Commented on 28.August 2011
Its good,but what's new with WPF! It can simply be done with winforms.Please give some example which describe the WPF specialty.
Commented on 30.August 2011
you Are very smart
Commented on 31.August 2011
good demo
Commented on 5.September 2011
worst example i didn't find need to demonstrate here. we can do in windows form only...
Commented on 5.September 2011
worst example i didn't find need to demonstrate here. we can do in windows form only...
Commented on 6.September 2011
Superb for beginners
Thanks for providing
Commented on 8.September 2011
Thank you very much. It was my 1st WPF sample.... Thanks again..... :)
Commented on 12.September 2011
Very useful tutorial... thanks :) I just wanna give 1 suggestion; if you could add a link @ Bottom for next page then it will be better..
Commented on 12.September 2011
WPF is for desktop application or web application???????
Commented on 13.September 2011
super very much useful for beginers
Commented on 13.September 2011
Commented on 14.September 2011
After creating an application I am not getting any control on toolbox to add on .xaml page.I need help.

Roshni Shah
Commented on 20.September 2011
Good Example for beginner...
Commented on 21.September 2011
very useful........ Thanks
Commented on 22.September 2011
very useful!:-)
Commented on 22.September 2011
It is Very useful for Beginners
Commented on 24.September 2011
Really nice. I am the beginner for learning Dot net but like to learn more
Commented on 27.September 2011
Nice article for beginners.
Mahesh Mane
Commented on 27.September 2011
It's cool

E-Mail (optional)