Previous MAUI-Features MAUI-StackLayout Next

Cross-Platform Concept in .NET MAUI

Cross-Platform Concept in .NET MAUI

The cross-platform concept in .NET MAUI (Multi-platform App UI) centers on a "Single Project" architecture that enables developers to target Android, iOS, Windows, and macOS from one unified codebase. This approach abstracts platform-specific complexities into a single shared project, dramatically reducing development time and maintenance overhead.

The "Single Project" Architecture

Unlike its predecessor, Xamarin.Forms—which required separate projects for each target platform—.NET MAUI uses a single .csproj file to manage all platforms.

  • Unified Entry Point: Every app starts at a single cross-platform entry point (MauiProgram.cs), which initializes the framework and sets up the main application shell regardless of the device it runs on.
  • Centralized Resources: You no longer need to manage multiple copies of images, fonts, or app manifests across different platform folders. MAUI allows you to specify shared resources in one location, and it automatically handles the generation of platform-specific assets during the build process.
  • Single App Manifest: Common application data like the app title, version, and unique ID is managed in a single place within the project file, which is then merged into native manifests at build time.

Handling Platform-Specific Code

While the goal is to share up to 95% of code, developers sometimes need to access unique native features or adjust UI for specific platforms.

  • The Platforms Folder: The project structure includes a Platforms folder with sub-folders for Android, iOS, MacCatalyst (macOS), and Windows. Code placed in these folders is "multi-targeted," meaning it is only compiled and shipped when building for that specific platform.
  • Conditional Compilation: Developers can use pre-processor directives (e.g., #if ANDROID) directly within shared files to execute code that only runs on a specific operating system.
  • Partial Classes and Methods: This modern C# feature allows you to define a method in shared code and provide its actual implementation in the platform-specific folders, ensuring a clean separation of concerns.

Native Performance and Look

MAUI is not a "lowest common denominator" framework; it prioritizes a native experience.

  • Native Rendering: When you define a Button in XAML, the framework maps it to a native UIButton on iOS or a WinUI Button on Windows. This ensures the app maintains the expected performance, accessibility, and visual style of each OS.
  • Unified API for Native Features: MAUI provides built-in, cross-platform APIs for common hardware features like GPS, sensors (accelerometer/gyroscope), secure storage, and camera access, allowing you to write one piece of code to interact with hardware across all four platforms.

Summary of Benefits

Feature Benefit
Code Reusability Share logic, models, and UI across all four platforms, saving up to 40% in development time.
Simplified Maintenance Fix a bug or update a feature in one project rather than four separate ones.
Hot Reload See UI changes instantly across multiple devices/simulators simultaneously without rebuilding.
Blazor Hybrid Option to mix web-based UI (HTML/CSS) with native capabilities for even broader code sharing with web apps.

By consolidating the development environment, .NET MAUI empowers smaller teams to reach a wide audience across mobile and desktop without sacrificing the performance of native development.

🌍 Cross-Platform Concept in .NET MAUI

Single Project Approach

.NET MAUI introduces a single project structure that allows developers to target multiple platforms (Android, iOS, Windows, macOS) from one codebase. This simplifies development and reduces duplication.

Key Benefits

  • 📦 One project file (.csproj) defines all platforms.
  • 🖼️ Shared resources (images, fonts, styles) automatically adapt to each platform.
  • 🔧 Platform-specific code organized under a Platforms/ folder.
  • ⚡ Faster development with Hot Reload and unified tooling in Visual Studio.
  • 🧩 Reuse of business logic, models, and MVVM patterns across platforms.

Project Layout

MyMauiApp/
 ├─ MyMauiApp.csproj
 ├─ App.xaml / App.xaml.cs
 ├─ MauiProgram.cs
 ├─ Resources/
 │   ├─ Images/
 │   ├─ Fonts/
 │   ├─ Styles/
 ├─ Views/
 ├─ ViewModels/
 ├─ Models/
 └─ Platforms/
     ├─ Android/
     ├─ iOS/
     ├─ MacCatalyst/
     └─ Windows/
  

How It Works

  • 🤖 Android → Uses Mono runtime and Android SDK.
  • 📱 iOS → Uses Mono runtime and integrates with Xcode.
  • 🖥️ macOS (Catalyst) → Shares iOS code with desktop adaptations.
  • 🪟 Windows → Runs on .NET CoreCLR with WinUI 3 integration.

Conclusion

The cross-platform concept in .NET MAUI ensures developers can build apps for mobile and desktop using a single project, maximizing code reuse and simplifying maintenance.

Back to Index
Previous MAUI-Features MAUI-StackLayout Next
*