Skip to content
Skillpedia
Mobile apps5.8k Β· #14585

maui-data-binding

What it does

This skill guides data binding in .NET MAUI apps, linking screen controls to the data behind them. It is for developers building MVVM apps who want safe, fast bindings.

When to use it

  • βœ“When you want a control in a MAUI page to show or edit a view model property.
  • βœ“When you need a value converter or a multi-value binding.
  • βœ“When you want to set up compiled bindings with a data type.

Skill link

https://github.com/dotnet/skills/blob/main/plugins/dotnet-maui/skills/maui-data-binding/SKILL.md

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/dotnet/skills/blob/main/plugins/dotnet-maui/skills/maui-data-binding/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute β†’

Example of what to ask your AI

β€œBind my MAUI login page entry fields to properties on the view model using compiled bindings.”

5 new skills a week. 1 minute to read.

How it works

The agent sets the data type on the page for compiled bindings, implements change notification in the view model, and picks the right binding mode for each control.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

.NET MAUI Data Binding

Wire UI controls to ViewModel properties with compile-time safety, correct change notification, and minimal overhead. Prefer compiled bindings everywhere and treat binding warnings as build errors.

When to Use

  • Adding x:DataType compiled bindings to a new or existing page
  • Implementing INotifyPropertyChanged or CommunityToolkit ObservableObject
  • Creating or consuming IValueConverter / IMultiValueConverter
  • Choosing the correct BindingMode for a control property
  • Setting BindingContext in XAML or code-behind
  • Using relative bindings (Self, AncestorType, TemplatedParent)
  • Applying StringFormat, FallbackValue, or TargetNullValue
  • Writing AOT-safe code bindings with SetBinding and lambdas (.NET 9+)

When Not to Use

  • CollectionView layouts / templates β€” use the maui-collectionview skill
  • Shell navigation parameters β€” use the maui-shell-navigation skill
  • Service registration / DI β€” use the maui-dependency-injection skill
  • Property-change-triggered animations β€” use built-in .NET MAUI animation APIs

Inputs

  • A .NET MAUI project targeting .NET 8 or later
  • XAML pages or C# code-behind where bindings are declared
  • A ViewModel class (or plan to create one)

Rules That Change the Answer

Apply these to every binding answer β€” they are the differences between "it compiles" and "it actually updates the UI".

Situation Do this Not this
Deciding where x:DataType goes Put it wherever a binding scope starts β€” the page/view root, and each DataTemplate Scattering it on arbitrary children that share the parent's BindingContext
A binding falls back to reflection (XC0022 / XC0023) Add the right x:DataType for that binding scope; for XC0023 remove the explicit x:DataType="{x:Null}" x:DataType="x:Object" to silence it β€” this disables compile-time checking
A DataTemplate inherits x:DataType from an outer scope (XC0024) Give the DataTemplate its own x:DataType Leaving it to resolve against the wrong type
ViewModel change notification ObservableObject + [ObservableProperty], or implement INotifyPropertyChanged A plain POCO base class β€” bindings will never update
Bindings show blank Check BindingContext is actually set Assuming the binding path is wrong
Enforcing compiled bindings Set MauiEnableXamlCBindingWithSourceCompilation to true, then <WarningsAsErrors>XC0022;XC0025</WarningsAsErrors> Promoting XC0025 without the switch if the project uses Source= / RelativeSource bindings

Do not restructure a ViewModel or add a converter that the user did not ask for and that fixes no real defect. Adding x:DataType is different: when you are already editing a page's bindings, recommending compiled bindings is in scope.


Compiled Bindings β€” x:DataType Placement

Compiled bindings are 8–20Γ— faster than reflection-based bindings and are required for NativeAOT / trimming. Enable them with x:DataType.

Placement rules

Set x:DataType only where BindingContext is set:

  1. Page / View root β€” where you assign BindingContext.
  2. DataTemplate β€” which creates a new binding scope.

Do not scatter x:DataType on arbitrary child elements. Adding x:DataType="x:Object" on children to escape compiled bindings is an anti-pattern β€” it disables compile-time checking and reintroduces reflection.

<!-- βœ… Correct: x:DataType at the page root -->
<ContentPage xmlns:vm="clr-namespace:MyApp.ViewModels"
             x:DataType="vm:MainViewModel">
    <StackLayout>
        <Label Text="{Binding Title}" />
        <Slider Value="{Binding Progress}" />
    </StackLayout>
</ContentPage>

<!-- ❌ Wrong: x:DataType scattered on children -->
<ContentPage x:DataType="vm:MainViewModel">
    <StackLayout>
        <Label Text="{Binding Title}" />
        <Slider x:DataType="x:Object" Value="{Binding Progress}" />
    </StackLayout>
</ContentPage>

DataTemplate always needs its own x:DataType

<CollectionView ItemsSource="{Binding People}">
    <CollectionView.ItemTemplate>
        <DataTemplate x:DataType="model:Person">
            <Label Text="{Binding FullName}" />
        </DataTemplate>
    </CollectionView.ItemTemplate>
</CollectionView>

Enforce binding warnings as errors

Warning Meaning
FAQ

What are compiled bindings?

They are bindings checked at build time, so mistakes show up before the app runs.

Does it cover navigation?

No. Navigation parameters are covered by a separate skill.

Does it cover ObservableObject?

Yes. It covers ObservableObject and INotifyPropertyChanged.

Details

Original description by the author

Guidance for .NET MAUI XAML and C# data bindings β€” compiled bindings, INotifyPropertyChanged / ObservableObject, value converters, binding modes, multi-binding, relative bindings, fallbacks, and MVVM best practices. USE FOR: setting up compiled bindings with x:DataType, implementing INotifyPropertyChanged or CommunityToolkit ObservableObject, creating IValueConverter / IMultiValueConverter, choosing binding modes, configuring BindingContext, relative bindings, binding fallbacks, StringFormat, code-behind SetBinding with lambdas, and enforcing XC0022/XC0025 warnings. DO NOT USE FOR: CollectionV

repo: dotnet/skills

Popularity

GitHub stars
5.8k
Ranking position
#14585
License
MIT
Updated
11/2/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills