
Description
Fix .NET MAUI UI layout, state, and automation issues: CollectionView not scrolling, DataTemplate binding problems, command binding back to page view models, Grid/FlexLayout responsive sizing, and binding-driven states. USE FOR: Auto vs Star Grid rows, avoiding ScrollView parents around CollectionView, rejecting HeightRequest fixes, replacing BindableLayout for large lists, stable AutomationIds, x:DataType item templates, RelativeSource AncestorType command bindings, EmptyView/loading/error states, responsive resources, and UI property bindings. DO NOT USE FOR: Shell routes, full accessibility audits, or vendor-specific controls.
SKILL.md
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:
Gridfor structured forms and dashboards.FlexLayoutfor wrapping content and responsive chip/card layouts.VerticalStackLayout/HorizontalStackLayoutfor simple linear groups.CollectionViewfor repeated data; avoid wrapping it inScrollView.
- Move repeated colors, spacing, and text styles into resources.
- Add
AutomationIdto important interactive elements. - Add loading, empty, error, and success states for data-driven screens.
For
CollectionViewloading/empty-state requests, show a visible loading element such asActivityIndicator, aCollectionView.EmptyView, and stableAutomationIdvalues 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/RowDefinitionsyntax. Do not embed{StaticResource ...}inside comma-separatedColumnDefinitionsstrings. - 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.
CollectionViewis not nested inside a parentScrollView.- The layout can scale across the intended device sizes.
More skills from the maui-labs repository
View all 32 skillsandroid-slim-bindings
create Android slim bindings for .NET
Jul 12.NETAndroidJavaKotlin +1devflow-automation
automate .NET MAUI app state
Jul 12.NETAutomationMAUIMobiledevflow-connect
diagnose DevFlow agent connectivity issues
Jul 12DebuggingMAUINetworkingdotnet-workload-info
discover MAUI workload metadata
Jul 12C#CLIEngineeringMAUIios-slim-bindings
create iOS slim bindings for MAUI
Jul 12.NETiOSMAUISwift +1maui-accessibility
implement accessibility in .NET MAUI apps
Jul 12.NETAccessibilityMAUIMobile +1
More from .NET (Microsoft)
View publishermultithreaded-task-migration
migrate MSBuild tasks to multithreaded mode
msbuild
Jul 12.NETEngineeringPerformanceanalyzing-dotnet-performance
analyze .NET code for performance anti-patterns
skills
Jul 12.NETCode AnalysisDebuggingPerformanceandroid-tombstone-symbolication
symbolicate .NET runtime frames in Android tombstones
skills
Jul 12.NETAndroidDebuggingMicrosoftapple-crash-symbolication
symbolicate .NET runtime frames in crash logs
skills
Jul 12.NETDebuggingiOSmacOS +1assertion-quality
evaluate assertion quality in test suites
skills
Jul 12Code AnalysisQATestingauthor-component
create and review Blazor components
skills
Jul 15.NETBlazorC#UI Components +1