Getting started with wpf
WPF (Windows Presentation Foundation) is Microsoft's recommended presentation technology for classic Windows desktop applications. WPF should not be confused with UWP (Universal Windows Platform) although similarities exist between the two.
WPF encourages data driven applications with a strong focus on multimedia, animation and data binding. Interfaces are created using a language called XAML (eXtensible Application Markup Language), a derivative of XML. XAML helps WPF programmers maintain separation of visual design and interface logic.
Unlike its predecessor Windows Forms, WPF uses a box model to layout all elements of the interface. Each element has a Height, Width and Margins and is arranged on screen relative to it's parent.
WPF stands for Windows Presentation Foundation and is also known under its Codename Avalon. It's a graphical Framework and part of Microsofts .NET Framework. WPF is pre-installed in Windows Vista, 7, 8 and 10 and can be installed on Windows XP and Server 2003.
Version 4.6.1 - December 2015
Hello World application
To create and run new WPF project in Visual Studio:
- Click File → New → Project
- Select template by clicking Templates → Visual C# → Windows → WPF Application and press OK:
- Open MainWindow.xaml file in Solution Explorer (if you don't see Solution Explorer window, open it by clicking View → Solution Explorer):
- In the XAML section (by default below Design section) add this code
Code should look like:
- Run the application by pressing F5 or clicking menu Debug → Start Debugging. It should look like: