Skip to content

1.5 WPF

WPF stands for Windows Presentation Foundation. It’s a UI (User Interface) framework developed by Microsoft for building Windows desktop applications.

1. πŸ’‘ What is WPF Used For?

WPF is used to create:

  • Rich desktop applications with graphical interfaces
  • Applications with modern UI designs (e.g., animations, styles, themes)
  • Data-driven apps (like dashboards, form-based apps)

1.1 Key Features

FeatureDescription
XAMLUses XML-based markup to design UI declaratively (.xaml files).
Data BindingConnects UI controls to data models (e.g., MVVM pattern).
Vector GraphicsUI scales smoothly on high-DPI screens.
Styles and TemplatesCustomize the appearance of controls.
AnimationsBuilt-in support for rich UI transitions.
Hardware AccelerationUses DirectX for fast rendering.

1.2 πŸ›  Example

XAML (UI layout):

<Window x:Class="MyApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Title="Hello WPF" Height="200" Width="300">
<Grid>
<Button Content="Click Me" Width="100" Height="30"/>
</Grid>
</Window>

C# (Code-behind):

public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}

1.3 Technologies it builds on:

  • .NET (Framework or Core/5+/6+/7+)
  • XAML for UI
  • MVVM (Model-View-ViewModel) is the common architecture

1.4 βœ… When to Use WPF

  • You’re building a Windows-only desktop app
  • You want a custom, modern UI
  • You need data binding, templates, animations, or advanced layout

1.5 ❌ When not to Use WPF

  • If you’re building cross-platform apps β†’ use MAUI, Electron, or web apps
  • If you only need basic UI β†’ WinForms might be simpler