MAUI UI Patterns
Use this skill when creating or reshaping a MAUI page or reusable component.
Prefer readable layouts, shared resources, stable automation hooks, and explicit
UI states over coordinate-based or screenshot-only UI.
Workflow
- Inspect the existing UI style: XAML, C# Markup, MauiReactor, or Blazor Hybrid.
If the requested page/component cannot be found but the user asked for a UI
pattern, still provide a self-contained snippet or create the requested file
at a sensible path instead of stopping with only a clarification request.
- Choose layout primitives based on content:
Grid for structured forms and dashboards.
FlexLayout for wrapping content and responsive chip/card layouts.
VerticalStackLayout / HorizontalStackLayout for simple linear groups.
CollectionView for repeated data; avoid wrapping it in ScrollView.
- Move repeated colors, spacing, and text styles into resources.
- Add
AutomationId to important interactive elements.
- Add loading, empty, error, and success states for data-driven screens.
For
CollectionView loading/empty-state requests, show a visible loading
element such as ActivityIndicator, a CollectionView.EmptyView, and stable
AutomationId values for loading/list/empty elements.
- Add basic accessibility hooks while building the UI; route deeper audits to
maui-accessibility.
- Verify with build plus DevFlow tree/screenshot when available.
Layout Guardrails
| Avoid |
Prefer |
| Absolute coordinates for normal app UI |
Grid, FlexLayout, and adaptive resources |
Nested ScrollView around CollectionView |
CollectionView scrolling directly |
Fixed HeightRequest to force list scrolling |
Star-sized Grid row so the list receives remaining space |
| Repeated inline colors/margins everywhere |
ResourceDictionary styles and spacing resources |
| Text-only UI automation |
Stable AutomationId values |
| One giant page without states |
Loading, empty, error, and content states |
BindableLayout for long or incremental lists |
CollectionView virtualization and incremental loading |
Example UI State Pattern
<Grid RowDefinitions="Auto,*">
<ActivityIndicator
AutomationId="products-loading"
IsRunning="{Binding IsBusy}"
IsVisible="{Binding IsBusy}" />
<CollectionView
Grid.Row="1"
AutomationId="products-list"
ItemsSource="{Binding Products}">
<CollectionView.EmptyView>
<Label
AutomationId="products-empty"
Text="No products found."
HorizontalOptions="Center"
VerticalOptions="Center" />
</CollectionView.EmptyView>
</CollectionView>
</Grid>
Typed DataTemplate Command Pattern
When a DataTemplate has an item x:DataType, bindings inside the template are
scoped to the item, not the page view model. Bind the row root to the item for
automation, and bind commands back to the page view model explicitly:
<CollectionView
AutomationId="products-list"
ItemsSource="{Binding Products}">
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="models:Product">
<Grid AutomationId="{Binding Sku, StringFormat='product-{0}'}">
<Grid.GestureRecognizers>
<TapGestureRecognizer
Command="{Binding Source={RelativeSource AncestorType={x:Type vm:ProductsViewModel}}, Path=SelectProductCommand}"
CommandParameter="{Binding .}" />
</Grid.GestureRecognizers>
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
Do not remove x:DataType just to reach the page command. Use an explicit
source (RelativeSource, x:Reference, or a binding proxy pattern that matches
the app's conventions) so compiled item bindings remain intact.
Responsive Patterns
- Use idiom- or platform-specific resources for spacing and column counts.
- Prefer adaptive layout decisions in XAML/resources over platform-specific code
unless behavior truly differs by platform.
- When column widths come from resources, prefer object-element
ColumnDefinition/RowDefinition syntax. Do not embed
{StaticResource ...} inside comma-separated ColumnDefinitions strings.
- Keep touch targets large enough for mobile even when the desktop layout is more
dense.
- Test small phone, tablet, and desktop widths when the page is meant to scale.
Validation Checklist
- Interactive controls have stable
AutomationIds.
- Repeated styling is moved to resources.
- Data-driven screens have empty/loading/error behavior.
CollectionView is not nested inside a parent ScrollView.
- The layout can scale across the intended device sizes.
1---2name: maui-ui-patterns3description: Fix MAUI UI layout, state, and automation issues. USE FOR: `CollectionView` scrolling, DataTemplate bindings, command bindings, Grid/FlexLayout sizing, binding-driven states, avoiding `ScrollView` parents, stable AutomationIds, `x:DataType`, EmptyView/loading/error states. DO NOT USE FOR: Shell routes, full accessibility, vendor-specific controls.4---56# MAUI UI Patterns78Use this skill when creating or reshaping a MAUI page or reusable component.9Prefer readable layouts, shared resources, stable automation hooks, and explicit10UI states over coordinate-based or screenshot-only UI.1112## Workflow13141. Inspect the existing UI style: XAML, C# Markup, MauiReactor, or Blazor Hybrid.15 If the requested page/component cannot be found but the user asked for a UI16 pattern, still provide a self-contained snippet or create the requested file17 at a sensible path instead of stopping with only a clarification request.182. Choose layout primitives based on content:19 - `Grid` for structured forms and dashboards.20 - `FlexLayout` for wrapping content and responsive chip/card layouts.21 - `VerticalStackLayout` / `HorizontalStackLayout` for simple linear groups.22 - `CollectionView` for repeated data; avoid wrapping it in `ScrollView`.233. Move repeated colors, spacing, and text styles into resources.244. Add `AutomationId` to important interactive elements.255. Add loading, empty, error, and success states for data-driven screens.26 For `CollectionView` loading/empty-state requests, show a visible loading27 element such as `ActivityIndicator`, a `CollectionView.EmptyView`, and stable28 `AutomationId` values for loading/list/empty elements.296. Add basic accessibility hooks while building the UI; route deeper audits to30 `maui-accessibility`.317. Verify with build plus DevFlow tree/screenshot when available.3233## Layout Guardrails3435| Avoid | Prefer |36| --- | --- |37| Absolute coordinates for normal app UI | `Grid`, `FlexLayout`, and adaptive resources |38| Nested `ScrollView` around `CollectionView` | `CollectionView` scrolling directly |39| Fixed `HeightRequest` to force list scrolling | Star-sized `Grid` row so the list receives remaining space |40| Repeated inline colors/margins everywhere | `ResourceDictionary` styles and spacing resources |41| Text-only UI automation | Stable `AutomationId` values |42| One giant page without states | Loading, empty, error, and content states |43| `BindableLayout` for long or incremental lists | `CollectionView` virtualization and incremental loading |4445## Example UI State Pattern4647```xml48<Grid RowDefinitions="Auto,*">49 <ActivityIndicator50 AutomationId="products-loading"51 IsRunning="{Binding IsBusy}"52 IsVisible="{Binding IsBusy}" />5354 <CollectionView55 Grid.Row="1"56 AutomationId="products-list"57 ItemsSource="{Binding Products}">58 <CollectionView.EmptyView>59 <Label60 AutomationId="products-empty"61 Text="No products found."62 HorizontalOptions="Center"63 VerticalOptions="Center" />64 </CollectionView.EmptyView>65 </CollectionView>66</Grid>67```6869## Typed DataTemplate Command Pattern7071When a `DataTemplate` has an item `x:DataType`, bindings inside the template are72scoped to the item, not the page view model. Bind the row root to the item for73automation, and bind commands back to the page view model explicitly:7475```xml76<CollectionView77 AutomationId="products-list"78 ItemsSource="{Binding Products}">79 <CollectionView.ItemTemplate>80 <DataTemplate x:DataType="models:Product">81 <Grid AutomationId="{Binding Sku, StringFormat='product-{0}'}">82 <Grid.GestureRecognizers>83 <TapGestureRecognizer84 Command="{Binding Source={RelativeSource AncestorType={x:Type vm:ProductsViewModel}}, Path=SelectProductCommand}"85 CommandParameter="{Binding .}" />86 </Grid.GestureRecognizers>87 </Grid>88 </DataTemplate>89 </CollectionView.ItemTemplate>90</CollectionView>91```9293Do not remove `x:DataType` just to reach the page command. Use an explicit94source (`RelativeSource`, `x:Reference`, or a binding proxy pattern that matches95the app's conventions) so compiled item bindings remain intact.9697## Responsive Patterns9899- Use idiom- or platform-specific resources for spacing and column counts.100- Prefer adaptive layout decisions in XAML/resources over platform-specific code101 unless behavior truly differs by platform.102- When column widths come from resources, prefer object-element103 `ColumnDefinition`/`RowDefinition` syntax. Do not embed104 `{StaticResource ...}` inside comma-separated `ColumnDefinitions` strings.105- Keep touch targets large enough for mobile even when the desktop layout is more106 dense.107- Test small phone, tablet, and desktop widths when the page is meant to scale.108109## Validation Checklist110111- Interactive controls have stable `AutomationId`s.112- Repeated styling is moved to resources.113- Data-driven screens have empty/loading/error behavior.114- `CollectionView` is not nested inside a parent `ScrollView`.115- The layout can scale across the intended device sizes.