Xamarin
01 / 02

Forms, XAML, MVVM & Data Binding

Forms, XAML, MVVM & Data Binding

Layered Architecture

Xamarin.Android/Xamarin.iOS give direct C# bindings to each platform's native APIs — write platform-specific UI in each one's native toolkit. Xamarin.Forms sits on top, providing a SHARED UI abstraction rendering to native controls on each platform — one UI codebase for both, at the cost of some platform-specific fidelity.

XAML + Code-Behind

<!-- MainPage.xaml -->
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms">
  <StackLayout>
    <Label Text="{Binding Greeting}" />
    <Button Text="Refresh" Command="{Binding RefreshCommand}" />
  </StackLayout>
</ContentPage>

XAML declares UI structure declaratively (like HTML), separate from the C# code-behind handling behavior — the same pattern WPF/UWP use.

Data Binding & MVVM

public class MainViewModel : INotifyPropertyChanged
{
    string greeting;
    public string Greeting
    {
        get => greeting;
        set { greeting = value; OnPropertyChanged(); }
    }
    public ICommand RefreshCommand { get; }
}

Model-View-ViewModel: the ViewModel exposes data/commands the View binds to — changing Greeting automatically updates the Label with no manual sync code. ViewModels can be unit-tested with zero actual UI involved, keeping business logic out of code-behind.

Keep your own version of these notes — editable, searchable, and organised by your stack.

Start free