.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> WPF >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Creating your first Windows Presentation Foundation Application

Posted By:Karthikeyan Anbarasan       Posted Date: February 28, 2013    Points: 200    Category: WPF    URL: http://www.dotnetspark.com  

In this article we are going to see how to create your first Windows Presentation Foundation (WPF) application using the Visual Studio 2012 IDE. Before proceeding further, our suggestion is to check our previous article on Windows Presentation Foundation which provides a fair idea on an overview about WPF and its uses
 

Introduction:

 

In this article we are going to see how to create your first Windows Presentation Foundation (WPF) application using the Visual Studio 2012 IDE. Before proceeding further, our suggestion is to check our previous article on Windows Presentation Foundation which provides a fair idea on an overview about WPF and its uses. Visual Studio 2012 Integrated Development Environment is basically a product from Microsoft which is used as a development environment for most of the application development which includes the application development for Windows Presentation Framework as well.
Let us see the step by step approach on creating a new Windows Presentation Framework application using the inbuilt templates that are available with Visual Studio 2012 IDE.

Steps:

Open Visual Studio 2012 IDE in an administrator mode (Right Click and select Run as an Administrator) and select File à New Project to select WPF application development template that is available under the Windows tab in the left menu as shown in the screen below.




With WPF application development we have different options to go with like we can develop a WPF based stand alone application or a WPF based Browser application. In this article we will see the stand alone application development for WPF and if we need to go with the browser based application then we need to select the WPF Browser application template that is available in the list of templates. Click on OK button to proceed further and we can see the project is created with a list of default files and folders as shown in the screen below.




This is an empty XAML application with only the Grid available by default, let us add some controls to the XAML code base so that we can see a nice user interface in our project sample as shown in the screen below. Here I have added a Textbox (for text inserting), a Textblock which is basically a label, and a button control to trigger the event as shown in the screen below.




Now in the XAML or in the code base change the exact data that is required which we normally do in our traditional stand alone application development by clicking on the button we should show the message to the end users. In the Input text box let us keep to enter the user name to welcome as well by providing a default text to the textblock as shown in the screen below.




XAML Code:

<Grid>
  <TextBlock HorizontalAlignment="Left" Margin="31,33,0,0" TextWrapping="Wrap" Text="Enter Name" VerticalAlignment="Top" Height="27" Width="71"/>
  <TextBox HorizontalAlignment="Left" Height="23" Margin="124,32,0,0" TextWrapping="Wrap" x:Name="txtInput" Text="" VerticalAlignment="Top" Width="217"/>
  <Button Content="Welcome Me" HorizontalAlignment="Left" Margin="31,91,0,0" VerticalAlignment="Top" Width="213" Click="Button_Click_1"/>

</Grid>


Now in the button click event write the code which will get the input from the user with the help of the textbox and show a message welcoming the user back as shown in the screen below.




C# Code:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WPFHelloworld
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            string strInput = txtInput.Text.ToString();
            MessageBox.Show("Welcome " + strInput + "!!!");
        }
    }
}



Now let us build and execute the application by simple pressing F5 key from the keyboard or using the Start play button at the tool bar menu and we can see the Visual Studio will build the application and open an interface to display the output as shown in the screen below.





 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend