# WPF — Windows Desktop UI Framework for .NET > Windows Presentation Foundation (WPF) is a free, open-source UI framework for building rich Windows desktop applications with XAML-based layouts and hardware-accelerated rendering. ## Install Save as a script file and run: # WPF — Windows Desktop UI Framework for .NET ## Quick Use ```bash # Create a new WPF app (.NET 8+) dotnet new wpf -n MyWpfApp cd MyWpfApp dotnet run ``` ## Introduction WPF is a UI framework for Windows desktop applications that uses XAML for declarative layout and C# for logic. It provides hardware-accelerated rendering via DirectX, a powerful data binding system, and a rich set of controls for building complex, resolution-independent desktop interfaces. ## What WPF Does - Renders vector-based UI through DirectX for resolution-independent, DPI-aware displays - Uses XAML markup to declare layouts, styles, animations, and data bindings - Provides a deep data binding engine with INotifyPropertyChanged and dependency properties - Supports styles, templates, and resource dictionaries for consistent theming - Enables custom controls, 3D rendering, and rich media integration ## Architecture Overview WPF separates presentation (XAML) from logic (C# code-behind or MVVM view models). The rendering pipeline uses a retained-mode composition engine backed by DirectX, handling layout, hit testing, and animation on a dedicated render thread. Dependency properties and routed events form the core of the property system, supporting data binding, styling, and event propagation through the visual tree. Templates let developers redefine the entire visual structure of any control. ## Self-Hosting & Configuration - Create projects with `dotnet new wpf` on .NET 8 or later (Windows only) - Organize shared resources in App.xaml and resource dictionaries - Use NuGet packages like CommunityToolkit.Mvvm for MVVM scaffolding - Publish as single-file, self-contained executables with `dotnet publish -r win-x64` - Integrate with MSIX packaging for Windows Store distribution and auto-updates ## Key Features - Two-way data binding with validation rules and value converters - Control templates allow complete visual redesign without subclassing - Storyboard animations and visual state transitions with easing functions - Built-in accessibility support via UI Automation and narrator integration - Interop with Win32, WinForms, and WebView2 for embedding web content ## Comparison with Similar Tools - **WinForms** — GDI-based with simpler API; WPF offers richer styling and vector rendering - **WinUI 3** — Modern native Windows UI; WPF has a larger ecosystem and long-term stability - **Avalonia** — Cross-platform XAML framework; WPF is Windows-only with deeper OS integration - **Electron** — Cross-platform via Chromium; WPF provides native performance without browser overhead - **MAUI** — Cross-platform .NET UI; WPF remains the standard for Windows-specific desktop apps ## FAQ **Q: Is WPF still actively maintained?** A: Yes. WPF is open-source on GitHub under the .NET Foundation and receives updates with each .NET release. **Q: Can WPF apps run on Linux or macOS?** A: No. WPF depends on DirectX and Windows APIs. For cross-platform, consider Avalonia or MAUI. **Q: What is MVVM and why use it with WPF?** A: Model-View-ViewModel separates UI from logic using data binding, making WPF apps testable and maintainable. **Q: How do I modernize an existing WPF app?** A: Migrate from .NET Framework to .NET 8, adopt CommunityToolkit.Mvvm, and embed WebView2 for hybrid scenarios. ## Sources - https://github.com/dotnet/wpf - https://learn.microsoft.com/dotnet/desktop/wpf/ --- Source: https://tokrepo.com/en/workflows/asset-71231402 Author: Script Depot