Previous MAUI-Project-Structure MAUI-Features Next

XAML in MAUI vs. WPF

Overview

Extensible Application Markup Language (XAML) is the declarative heart of both Windows Presentation Foundation (WPF) and .NET Multi-platform App UI (.NET MAUI), yet they represent two distinct evolutions of the same technology. At a high level, WPF is a mature, Windows-only framework optimized for high-performance desktop graphics using DirectX. In contrast, .NET MAUI is a modern, cross-platform evolution of Xamarin.Forms designed to run a single codebase across Windows, macOS, iOS, and Android. While they share the same XML-based syntax, their vocabularies and underlying rendering engines differ significantly.

At a high level, WPF is a mature, Windows-only framework optimized for high-performance desktop graphics using DirectX. In contrast, .NET MAUI is a modern, cross-platform evolution of Xamarin.Forms designed to run a single codebase across Windows, macOS, iOS, and Android. While they share the same XML-based syntax, their vocabularies and underlying rendering engines differ significantly.

WPF XAML

  • 🏢 Windows-only framework for desktop applications.
  • 🎨 Rich styling, templating, and data binding features tailored for desktop UI.
  • 🖥️ Deep integration with Windows Presentation Foundation (vector graphics, animations, triggers).
  • 🔧 Mature ecosystem with extensive third-party controls.
  • 📌 Focused on desktop scenarios window management, desktop resources, advanced rendering.

MAUI XAML

  • 🌍 Cross-platform Android, iOS, macOS, Windows.
  • 📱 Derived from Xamarin.Forms, simplified for mobile + desktop hybrid apps.
  • 🔗 Shares MVVM patterns and data binding with WPF, but lighter.
  • 🎨 Styles and resources are portable across platforms, with platform-specific overrides.
  • ⚡ Focused on mobile-first scenarios navigation via Shell, responsive layouts, touch input.

1. Control Naming and Structural Differences

The most immediate difference you will encounter is in the names of the UI elements. WPF uses names rooted in classic Windows desktop terminology, while MAUI uses more abstract, platform-agnostic names.

Feature WPF Control .NET MAUI Control
Root Element Window ContentPage (nested in a Shell or Window)
Text Display TextBlock or Label Label
Text Input TextBox (single/multi-line) Entry (single) or Editor (multi-line)
Layout Container StackPanel StackLayout (or specialized VerticalStackLayout / HorizontalStackLayout)
Scrolling ScrollViewer ScrollView
Buttons Button (uses Click event) Button (uses Clicked event)

2. Layout and Sizing Logic

The way elements are measured and positioned differs to accommodate mobile screens versus resizable desktop windows:

  • Property Names WPF uses Height and Width to specify exact sizes. .NET MAUI uses HeightRequest and WidthRequest, which act as "requests" to the layout engine rather than strict requirements.
  • Alignment WPF relies on HorizontalAlignment and VerticalAlignment. .NET MAUI uses HorizontalOptions and VerticalOptions, which often include expansion flags (e.g., CenterAndExpand) to handle dynamic mobile screen orientations.
  • Borders In WPF, many controls have built-in BorderThickness and CornerRadius properties. In .NET MAUI, you must typically wrap a control in a separate Border or Frame container to achieve these effects.

3. Namespaces and Project Structure

The "dialect" of XAML is defined by the XML namespaces at the top of your file:

  • WPF Namespace:http://schemas.microsoft.com/winfx/2006/xaml/presentation.
  • MAUI Namespace: http://schemas.microsoft.com/dotnet/2021/maui.

Project Files A WPF app is usually a single-platform project. A .NET MAUI app uses a single project structure where a Platforms folder contains specific code for iOS, Android, and Windows, while the XAML remains shared across all of them.

4. Rendering Engines

WPF (DirectX) WPF renders directly using DirectX. It excels at complex 2D/3D graphics, vector animations, and pixel-perfect layouts on Windows.

MAUI (Native Handlers) MAUI uses an abstraction layer called Handlers. When you define a Button in MAUI XAML, the framework maps it to a UIButton on iOS, a Widget.Button on Android, and a WinUI Button on Windows. This ensures the app feels native on every device but can make pixel-perfect cross-platform consistency harder to achieve.

5. Tooling and Designer Support

WPF Features a robust Visual Designer in Visual Studio that allows for drag-and-drop UI creation and a "What You See Is What You Get" (WYSIWYG) experience.

MAUI Does not have a drag-and-drop designer. Instead, it relies on XAML Hot Reload, which allows you to see UI changes in real-time on a running emulator or device as you type the code.

Summary Table WPF vs. MAUI XAML

Feature WPF .NET MAUI
Primary Platform Windows Desktop iOS, Android, macOS, Windows
XAML Dialect Desktop-focused (Window, TextBlock) Mobile-first/Universal (ContentPage, Label)
Graphics Engine DirectX (High performance) Native OS controls (via Handlers)
Visual Designer Drag-and-drop support XAML Hot Reload only
Data Binding Standard {Binding} Standard {Binding} + Compiled Bindings {x:Bind}

While the transition for a WPF developer to MAUI is relatively straightforward due to shared concepts like MVVM (Model-View-ViewModel) and Data Binding, you cannot simply copy-paste XAML files from one to the other without significant renaming and structural adjustments.

Key Differences

Aspect WPF MAUI
Platform Windows desktop only Cross-platform (Android, iOS, macOS, Windows)
UI richness Advanced desktop graphics, triggers, animations Mobile-friendly controls, responsive layouts
Navigation Window-based, manual navigation Shell-based, route navigation
Resources Desktop resource dictionaries Shared resources with platform overrides
Ecosystem Mature, stable, Windows-focused Newer, evolving, cross-platform

Conclusion

WPF XAML is best for powerful Windows desktop applications with advanced UI needs. MAUI XAML is ideal for cross-platform apps where code and UI can be shared across mobile and desktop.

Back to Index
Previous MAUI-Project-Structure MAUI-Features Next
*