wpf Hello World application


Example

To create and run new WPF project in Visual Studio:

  1. Click File → New → Project

New project

  1. Select template by clicking Templates → Visual C# → Windows → WPF Application and press OK:

enter image description here

  1. Open MainWindow.xaml file in Solution Explorer (if you don't see Solution Explorer window, open it by clicking View → Solution Explorer):

enter image description here

  1. In the XAML section (by default below Design section) add this code
<TextBlock>Hello world!</TextBlock>

inside Grid tag:

enter image description here

Code should look like:

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApplication1"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <TextBlock>Hello world!</TextBlock>
    </Grid>
</Window>
  1. Run the application by pressing F5 or clicking menu Debug → Start Debugging. It should look like:

enter image description here