mobile5 min read

Xamarin Tutorial: Learn .NET Mobile from Scratch (2026)

Xamarin Tutorial: Learn .NET Mobile from Scratch (2026)

Published:  |  Category: Mobile  |  Reading time: ~15 min
Xamarin Tutorial: Learn .NET Mobile from Scratch (2026)

Xamarin was Microsoft's answer to cross-platform mobile development before .NET MAUI took over. I built two enterprise apps with Xamarin.Forms and learned to appreciate its strengths — C# shared code, XAML for UI, and MVVM out of the box. The development experience is polished if you are already in the .NET ecosystem, and Xamarin's ability to call native APIs directly when needed gave me flexibility that web-based hybrid frameworks could not match. This tutorial covers Xamarin.Forms (now in maintenance mode but still widely used in enterprise), with attention to the patterns that made my projects maintainable across iOS and Android.

Setting Up Xamarin Development Environment

Xamarin development requires Visual Studio — the Community edition is free. On Windows, you can target Android directly; for iOS, you need a Mac build host connected via SSH or a network. Install the Mobile development with .NET workload in the Visual Studio installer. Create a new project using the Mobile App (Xamarin.Forms) template. The solution has a shared project (or .NET Standard library) for business logic and platform-specific projects for Android and iOS. The App.xaml and App.xaml.cs files define the application entry point, and MainPage.xaml is your first screen.

// Create via: Visual Studio > New Project > Mobile App (Xamarin.Forms)
// Solution structure:
// MyApp.sln
// MyApp (shared)/App.xaml
// MyApp.Android/MainActivity.cs
// MyApp.iOS/AppDelegate.cs

XAML and Code-Behind Fundamentals

XAML is the declarative markup language for defining Xamarin.Forms UI. It maps XML elements to C# classes — ContentPage, StackLayout, Label, Button, Entry. Attributes map to properties: Text="Hello" sets the Label's Text property. Event handlers like Clicked="OnButtonClicked" are wired in the code-behind file (MainPage.xaml.cs). XAML supports data binding with {Binding PropertyName} syntax, converters for value transformations, and static resources for shared styles. The layout system uses StackLayout (vertical stacking), Grid (rows and columns), FlexLayout, and AbsoluteLayout.



  

MVVM Architecture in Xamarin.Forms

MVVM is the recommended pattern for Xamarin.Forms. The Model represents data, the View is the XAML page, and the ViewModel contains the logic and state. ViewModels implement INotifyPropertyChanged and expose properties that the View binds to. Use an MVVM library like Prism or the built-in CommunityToolkit.Mvvm to reduce boilerplate — they provide ObservableObject, RelayCommand, and source generators. Data binding connects View to ViewModel: the ViewModel exposes an ObservableCollection and commands, and the View binds to them. The BindingContext property on the page ties it all together.

public class MainViewModel : ObservableObject {
  [ObservableProperty] private string _name;
  [RelayCommand] private async void Save() { await Shell.Current.GoToAsync(".."); } }

Navigation with Shell

Xamarin.Forms Shell provides a container for flyout and tab-based navigation with URI routing. Define routes in AppShell.xaml using ShellContent for pages. Navigate with Shell.Current.GoToAsync("route") — it handles the navigation stack, back button behavior, and passes query parameters via IQueryAttributable or dictionary arguments. Shell also gives you a built-in search handler and flyout customization. For simple push navigation, Navigation.PushAsync(new SomePage()) still works, but Shell is preferred for its URI-based approach and proper lifecycle management.


  

// Navigate via code: await Shell.Current.GoToAsync("//settings");

Accessing Platform Features with DependencyService

Xamarin.Forms provides DependencyService for accessing platform-specific code from shared code. Define an interface in the shared project, implement it in each platform project, and register it with [assembly: Dependency(typeof(AndroidImpl))]. Call DependencyService.Get().Speak("Hello") from shared code. Modern Xamarin projects use Dependency Injection with IServiceProvider instead of DependencyService. For complex native integrations, write custom renderers or platform effects that customize the appearance and behavior of cross-platform controls.

public interface ITextToSpeech { void Speak(string text); }
[assembly: Dependency(typeof(TextToSpeechImpl))]
public class TextToSpeechImpl : ITextToSpeech { public void Speak(string text) => // native TTS code }

Testing, App Center, and Deployment

Xamarin apps can be tested with NUnit or xUnit for unit tests, and Xamarin.UITest for UI automation. For distribution, Visual Studio App Center is the recommended platform — it handles building, testing on real devices, distributing to testers, and collecting crash reports and analytics. To publish, configure signing in the Android project properties (keystore for Android) and the iOS project's Info.plist (provisioning profile). App Center automatically increments build numbers and distributes via groups. Note that Xamarin.Forms is in maintenance mode — new projects should use .NET MAUI, but Xamarin.Forms apps remain supported.

// App Center build configuration
appcenter build queue --app Owner/MyApp --branch main --token XXXXX

Frequently Asked Questions

Is Xamarin.Forms still relevant in 2026?

Xamarin.Forms is in maintenance mode, meaning no new features, only security and critical fixes. However, many enterprise apps still use it. New projects should use .NET MAUI, which is the successor with better performance and more modern APIs.

How does Xamarin performance compare to native?

Xamarin has some overhead from the Mono runtime and platform abstraction layer. For most business apps, the difference is negligible. Performance-critical apps (games, real-time processing) should use native or platforms with tighter hardware access.

Can I share code between Xamarin and other .NET projects?

Yes. Shared code in a .NET Standard library can be reused across Xamarin.Android, Xamarin.iOS, ASP.NET Core, and WPF applications. Business logic, data models, and service interfaces are all shareable.

What is the difference between Xamarin.Forms and Xamarin.Native?

Xamarin.Forms provides a single API that maps to native controls across platforms — write once, render natively. Xamarin.Native (Xamarin.Android + Xamarin.iOS) lets you write platform-specific code with full access to native APIs but requires separate UI code per platform.

Originally published on Ayodhyyya. Last updated June 1, 2026.