Previous MAUI-AbsoluteLayout MAUI-Custom-Layouts Next

๐Ÿ“ Layouts in .NET MAUI โ€“ BindableLayout

BindableLayout in .NET MAUI

.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.

๐Ÿ”‘ Key Features of BindableLayout

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.

๐Ÿ“˜ Example Code

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.

โœ… Why Choose BindableLayout?

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.

๐Ÿ“Œ Common Use Cases

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.

โš ๏ธ Considerations

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.

BindableLayout vs CollectionView in .NET MAUI

comparison between BindableLayout and CollectionView in .NET MAUI so you can clearly see when each is the better choice.

โš–๏ธ BindableLayout vs CollectionView

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)

โœ… When to Choose Each

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.

๐Ÿ“˜ Example Contrast

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.

Back to Index
Previous MAUI-AbsoluteLayout MAUI-Custom-Layouts Next
*