First open "Visual studio".Click on File-> New -> Project
Step-2
Double click on Visual C# from installed templates.Select the WPF application->Type the Application Name ->Click on OK.
After clicking on OK, below screen appears.
Step-3
Visual studio adds some files to the solution
More Info
For every window created, two files are associated with it.
.XAML
.XAML.cs
1) .XAML : This is very much similar to a .aspx file in ASP.NET. This file will contain two parts.
Design part: Design part will contain the respective physical appearance for the design code.
Source part: Source part will contain XAML design code for creating the user interface elements.
2). XAML.cs : This is similar to .aspx.cs file in ASP.NET and this will contain complete programming part code.
Code
Now design the form like below with the coding.
[csharp] </Window.Resources>
<Grid Background="#FF8AF159" ToolTip="Click Here">
<Button Content="Button" HorizontalAlignment="Left" Margin="121,164,0,0" VerticalAlignment="Top" Width="198" Height="50" Click="Button_Click" FontSize="25" FontFamily="{DynamicResource FontFamily1}" FontStretch="UltraCondensed" RenderTransformOrigin="0.5,0.5" Background="{DynamicResource {x:Static SystemColors.ActiveCaptionBrushKey}}">
<Button.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleY="1" ScaleX="1"/>
<SkewTransform AngleY="0" AngleX="0"/>
<RotateTransform Angle="0"/>
<TranslateTransform X="2" Y="2"/>
</TransformGroup>
</Button.RenderTransform>
</Button>
</Grid>
</Window>
[/csharp]
In above form, button control is taken for creating a simple WPF Application.
Now write the code in code behind file (MainWindow.xmal.cs)
[csharp]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 WPFApp1
{
///
<summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("Hello WPF Application");
}
}[/csharp]
Further
Now build the application and press F5 to run the application. Then following screen appears.
If clicked on the button in above screen or window, the result appears as: