| MAUI-AbsoluteLayout | MAUI-Custom-Layouts | |
๐ Layouts in .NET MAUI โ BindableLayout |
.NET MAUIโs BindableLayout is a powerful way to bind a collection of data directly to any layout (like StackLayout or FlexLayout) and automatically generate child views using a DataTemplate. Itโs ideal when you want lightweight, flexible, data-driven UI without needing a full CollectionView.
ItemsSource Binding: Bind any IEnumerable collection to the layout.
ItemTemplate: Define how each item should look using a DataTemplate.
ItemTemplateSelector: Dynamically choose different templates at runtime for different items.
Lightweight Alternative: Unlike CollectionView, it doesnโt add scrolling or virtualization overhead.
Empty State Support: Can display a message or placeholder when the collection is empty.
xml
<StackLayout BindableLayout.ItemsSource="{Binding People}">
<BindableLayout.ItemTemplate>
<DataTemplate>
<Label Text="{Binding Name}"
FontSize="18"
TextColor="DarkBlue"/>
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>
Here, the StackLayout is populated with Label elements for each person in the People collection.
Each item uses the Name property from the bound data.
Flexibility: Works with any layout (StackLayout, Grid, FlexLayout), not just list controls.
Lightweight: Perfect when you donโt need scrolling, selection, or virtualization.
Custom Layouts: Lets you arrange items in non-standard ways (e.g., wrapping tags, badges).
Quick Prototyping: Easy to set up for small collections without the complexity of CollectionView.
Tag Clouds / Chips: Display dynamic sets of labels or buttons.
Dashboards: Populate panels with widgets bound to data.
Forms: Generate input fields dynamically from a model.
Badges or Status Indicators: Show a collection of icons or indicators.
Lightweight Lists: When you need a simple list but donโt require scrolling or advanced features.
No Virtualization: Not suitable for very large datasets (use CollectionView instead).
No Built-in Scrolling: Must wrap inside a ScrollView if scrolling is needed.
Performance: Best for small to medium collections.
In short: Use BindableLayout when you want a data-driven, lightweight, flexible UI inside any layout container. Itโs perfect for tags, badges, dashboards, and dynamic forms, but for large, scrollable lists, stick with CollectionView.
comparison between BindableLayout and CollectionView in .NET MAUI so you can clearly see when each is the better choice.
| Feature | BindableLayout | CollectionView |
|---|---|---|
| Purpose | Lightweight way to bind a collection to any layout (StackLayout, FlexLayout, Grid) | Full-featured list control designed for large, scrollable datasets |
| ItemsSource | Yes, binds to any IEnumerable | Yes, binds to any IEnumerable |
| ItemTemplate | Yes, supports DataTemplate and ItemTemplateSelector | Yes, supports DataTemplate, Selector, and advanced templating |
| Scrolling | No built-in scrolling (wrap in ScrollView if needed) | Built-in scrolling (vertical/horizontal) |
| Virtualization | โ No virtualization โ not suitable for large datasets | โ Virtualization โ efficient with thousands of items |
| Selection | โ No selection support | โ Supports single/multiple selection |
| Layout Options | Flexible: can use any layout container | Fixed layouts (linear, grid) but optimized for performance |
| Performance | Best for small/medium collections | Optimized for large collections |
| Use Cases |
- Tag clouds - Dashboards - Dynamic forms - Badges/indicators |
- Long lists - Infinite scrolling - Data-heavy apps (contacts, feeds) |
Choose BindableLayout if you want a lightweight, flexible, data-driven UI inside any layout container. Perfect for tags, badges, dashboards, or small lists where scrolling and virtualization arenโt critical.
Choose CollectionView if you need a scrollable, performant list with selection, grouping, and virtualization. Best for feeds, catalogs, or large datasets.
BindableLayout (tags inside a FlexLayout):
xml
<FlexLayout BindableLayout.ItemsSource="{Binding Tags}" Wrap="Wrap">
<BindableLayout.ItemTemplate>
<DataTemplate>
<Button Text="{Binding}" Margin="5"/>
</DataTemplate>
</BindableLayout.ItemTemplate>
</FlexLayout>
CollectionView (scrollable list of people):
xml
<CollectionView ItemsSource="{Binding People}">
<CollectionView.ItemTemplate>
<DataTemplate>
<StackLayout Padding="10">
<Label Text="{Binding Name}" FontSize="18"/>
<Label Text="{Binding Age}" FontSize="14"/>
</StackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
๐ In short:
BindableLayout = flexible, lightweight, small collections.
CollectionView = powerful, scrollable, large datasets.
| MAUI-AbsoluteLayout | MAUI-Custom-Layouts | |