Xamarin / .NET MAUI Simple Todo App - Xamarin-maui Typing CST Test
Loading…
Xamarin / .NET MAUI Simple Todo App — Xamarin-maui Code
Demonstrates a simple Xamarin / .NET MAUI app with a Todo list, adding tasks via UI, and displaying them in a ListView.
// MainPage.xaml.cs
using System.Collections.ObjectModel;
using Microsoft.Maui.Controls;
namespace TodoApp
{
public partial class MainPage : ContentPage
{
ObservableCollection<string> todos = new ObservableCollection<string>();
public MainPage()
{
InitializeComponent();
TodoList.ItemsSource = todos;
}
void AddTodo_Clicked(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(TodoEntry.Text))
{
todos.Add(TodoEntry.Text);
TodoEntry.Text = string.Empty;
}
}
}
}
// MainPage.xaml
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TodoApp.MainPage">
<StackLayout Padding="20">
<Entry x:Name="TodoEntry" Placeholder="New Todo" />
<Button Text="Add" Clicked="AddTodo_Clicked" />
<ListView x:Name="TodoList" />
</StackLayout>
</ContentPage>Xamarin-maui Language Guide
Xamarin.MAUI (Multi-platform App UI) is a cross-platform framework for building native mobile, desktop, and tablet applications using C# and .NET with a single shared codebase.
Primary Use Cases
- ▸Cross-platform mobile applications (iOS, Android)
- ▸Cross-platform desktop applications (Windows, macOS)
- ▸Enterprise business apps with shared codebase
- ▸Apps requiring native device integration
- ▸Rapid prototyping of multi-platform UIs
Notable Features
- ▸Single shared project for all platforms
- ▸Native UI rendering and access to platform APIs
- ▸XAML for declarative UI and MVVM support
- ▸Hot reload for UI and code changes
- ▸Integration with .NET ecosystem and libraries
Origin & Creator
Developed by Microsoft, evolving from Xamarin.Forms, officially released as .NET MAUI in 2022.
Industrial Note
Xamarin.MAUI is ideal for enterprises and developers targeting multiple platforms who want to maximize code sharing while retaining native performance and UI fidelity.
Quick Explain
- ▸Xamarin.MAUI allows developers to write apps for iOS, Android, Windows, and macOS using a single project.
- ▸Uses .NET and C# with XAML for UI definitions.
- ▸Supports native performance and access to platform-specific APIs.
- ▸Includes tools for MVU, MVVM, and code-behind architecture patterns.
- ▸Integrates with .NET libraries, Blazor, and third-party packages.
Core Features
- ▸Cross-platform UI and controls
- ▸Dependency injection support
- ▸Data binding and MVVM patterns
- ▸Access to device hardware and sensors
- ▸Integration with REST APIs and local databases
Learning Path
- ▸Learn C# and .NET basics
- ▸Understand XAML and MVVM
- ▸Build simple MAUI apps for mobile
- ▸Add multi-platform support and native features
- ▸Integrate APIs, databases, and authentication
Practical Examples
- ▸Build a multi-platform todo app
- ▸Create a business CRM mobile + desktop app
- ▸Implement camera and GPS integration
- ▸Add authentication with OAuth or JWT
- ▸Consume REST APIs and display data with MVVM
Comparisons
- ▸Xamarin.MAUI vs Xamarin.Forms: MAUI unifies multi-platform projects
- ▸Xamarin.MAUI vs React Native: MAUI C#/.NET, React Native JavaScript
- ▸Xamarin.MAUI vs Flutter: MAUI uses native controls, Flutter uses custom rendering
- ▸Xamarin.MAUI vs Swift/Kotlin native: MAUI single codebase, native apps platform-specific
- ▸Xamarin.MAUI vs Uno Platform: MAUI targets mobile & desktop, Uno adds Web/WebAssembly support
Strengths
- ▸Maximizes code reuse across platforms
- ▸Native performance on iOS, Android, Windows, macOS
- ▸Strong support for MVVM and reactive programming
- ▸Extensive .NET ecosystem and libraries
- ▸Microsoft-supported and well-documented
Limitations
- ▸Larger app size compared to native apps
- ▸Platform-specific UI adjustments sometimes needed
- ▸Slower startup compared to fully native apps
- ▸Smaller community than native Swift/Kotlin
- ▸Learning curve for developers unfamiliar with .NET/XAML
When NOT to Use
- ▸For simple web apps (use Blazor or web frameworks)
- ▸If targeting only one platform with native features
- ▸When very lightweight apps are needed
- ▸When team lacks C#/.NET experience
- ▸For GPU-intensive games (Unity/Unreal may be better)
Cheat Sheet
- ▸dotnet new maui -n MyApp - create project
- ▸dotnet build - build project
- ▸dotnet run - run app locally
- ▸dotnet publish - prepare for deployment
- ▸Use XAML bindings: {Binding PropertyName} for UI updates
FAQ
- ▸Is MAUI open-source? -> Yes, MIT license.
- ▸Does MAUI support all platforms? -> iOS, Android, Windows, macOS (partial for Linux with community tooling).
- ▸Can MAUI apps access native APIs? -> Yes, via dependency services or partial classes.
- ▸Is MAUI suitable for enterprise apps? -> Yes, widely used in business applications.
- ▸How to debug MAUI apps? -> Visual Studio debugger, device/emulator logs, and Hot Reload.
30-Day Skill Plan
- ▸Week 1: Setup MAUI project and build first page
- ▸Week 2: Implement MVVM and data binding
- ▸Week 3: Add navigation and multiple pages
- ▸Week 4: Integrate APIs and platform-specific services
- ▸Week 5: Test, optimize, and deploy cross-platform
Final Summary
- ▸Xamarin.MAUI is a cross-platform framework using C#/.NET.
- ▸Supports mobile and desktop platforms with native performance.
- ▸MVVM and XAML provide structured UI and data binding.
- ▸Integrates with .NET ecosystem and third-party libraries.
- ▸Ideal for enterprises and developers targeting multiple platforms with shared code.
Project Structure
- ▸Platforms/ - platform-specific code (iOS, Android, Windows, macOS)
- ▸Resources/ - images, fonts, styles
- ▸Views/ - XAML pages and layouts
- ▸ViewModels/ - data and business logic
- ▸App.xaml & App.xaml.cs - application entry point
Monetization
- ▸Open-source framework under MIT
- ▸Enterprise apps can monetize via stores
- ▸Integrate with ads or subscription services
- ▸Reduces development cost with shared codebase
- ▸Deploy on multiple platforms without rewriting code
Productivity Tips
- ▸Use Hot Reload for rapid iteration
- ▸Leverage MVVM and CommunityToolkit.MVVM
- ▸Reuse controls and resources
- ▸Profile apps on multiple platforms
- ▸Use dependency injection for modular code
Basic Concepts
- ▸Page - a screen/view in the app
- ▸Layout - container for arranging UI elements
- ▸Control - interactive UI element (Button, Label, Entry)
- ▸ViewModel - holds UI data and logic (MVVM)
- ▸Binding - connects UI elements to ViewModel properties
Official Docs
- ▸https://learn.microsoft.com/dotnet/maui/
- ▸Xamarin.MAUI GitHub repository
- ▸Microsoft Learn tutorials for MAUI