Bookmark and Share Share...    Subscribe to this feed Feed   About me...


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!




 Comments on this article

Show all comments
Sean
Commented on 2.August 2010
This is awesome advice
Anil
Commented on 2.August 2010
Nice tutorial for the beginners..
Bikant
Commented on 2.August 2010
very good
bindu
Commented on 3.August 2010
hey nice but need more examples!!!! also pls provide info on more topics...the way u have explained is really fantastic...very clear to understand for beginers like me
thank u
akond rahman
Commented on 4.August 2010
cool cool cool
WPF_Beginer
Commented on 5.August 2010
Hi,
When I run the application, i get an "XAMLParse exception unhandled" error. Why is it so ? Also, I don't have SP1 installed on my system. Could that be the reason?

Avijit
Commented on 6.August 2010
Very good site
Bhargava
Commented on 10.August 2010
Its a very good site to lear the WPF, even during the first 10 minute of starting, i get fair idea about WPF and was able to create this simple application.
Thanks dud,
Bhargava Pandey
www.bhargavapandey.com
Qualitatserz...
Commented on 12.August 2010
I made it using Visual Basic 2008 Express and works exactly the same!!!
sree
Commented on 13.August 2010
gud article
Sandeep...
Commented on 16.August 2010
very good article thanks christian
Praveen Kumar
Commented on 17.August 2010
Hello WPF !

i successfully done my first WPF Program....Cheers !!!!!!!!!!!!!
Siva...
Commented on 18.August 2010
Gr8 my first WPF Started.. Here we go!!!
madu
Commented on 18.August 2010
wow...excellent.need more articles from you in future too
vijay
Commented on 19.August 2010
Superb
shrishail
Commented on 20.August 2010
Can I know the difference between create the WPF appliction in Visual Studio and in Expression Studio?
kirankumar...
Commented on 20.August 2010
Great , superb
prasobh.k
Commented on 21.August 2010
Excellent.visit my site http://www.microemail.co.cc
fsdf
Commented on 21.August 2010
<a href="">adasaS</a>
Rahul panchal
Commented on 22.August 2010
if text box is null, so i want execute onother error screen than what shall i do?
CHRISTIAN
Commented on 23.August 2010
I apprieciate your feedback but I cant explain it anymore in depth because I just copy and pasted this from another website
Shine
Commented on 31.August 2010
Nice one to start with!
rajeshp
Commented on 1.September 2010
good & very nice...
Ilviann Zed
Commented on 1.September 2010
Didn't work in SharpDevelop.
Leena
Commented on 2.September 2010
very good n very easy to learn..

Name
E-Mail (optional)
Comment
About Christian Moser