🏗️
MauiReactor
  • What is MauiReactor?
  • What's new in Version 2
  • What's new in Version 3
  • Getting Started
  • Getting Started Version 2
  • Components
    • State-less Components
    • Stateful Components
      • Inline Components
    • Component life-cycle
    • Component Properties
    • Component with children
    • Component Parameters
    • Theming
    • Navigation
      • NavigationPage
      • Shell
      • Back button
    • Controls
      • Button
      • RadioButton
      • FlyoutPage
      • CollectionView
        • Interactions
        • Layout
        • Selection
        • Empty view
        • Scrolling
        • Grouping
      • IndicatorView
      • Picker
      • Shell
      • Label
    • Wrap 3rd party controls
      • Lottie animations
      • Provide DataTemplate to native controls
    • Accessing native controls
    • Animation
      • Property-Based
      • AnimationController
      • Timer
    • Graphics
      • CanvasView control
    • Window
    • Testing
    • XAML Integration
  • Deep dives
    • Native tree and Visual tree
    • Dependency injection
    • Working with the GraphicsView
    • Migrating from MVVM Model
    • Using XAML Resources
    • Behaviors
  • resources
    • Source and Sample Applications
  • Q&A
    • How to deal with state shared across Components?
    • Does this support ObservableCollection for CollectionView?
    • Do we need to add states to create simple animations such as ScaleTo, FadeTo, etc on tap?
    • How to deal with custom dialogs/popups?
  • How to create a Menu/ContextMenu?
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
  1. Components
  2. Controls

CollectionView

This page describes how to create a CollectionView in MauiReactor

PreviousFlyoutPageNextInteractions

Last updated 9 months ago

Was this helpful?

The .NET Multi-platform App UI (.NET MAUI) is a view for presenting lists of data using different layout specifications. It aims to provide a more flexible, and performant alternative to .

Official documentation: MauiReactor sample app:

Display data

Use the method ItemsSource() to link a collection of items and to define how each item is displayed.

Bind the CollectionView to an IEnumerable (i.e. List or Array) you do not need to modify the collection (read-only collections). If you want to update the list, adding or removing items, use an ObservableCollection instead.

For example:

protected override void OnMounted()
{
    var person1 = new Person("John", "Doe", new DateTime(1980, 5, 10));
    var person2 = new Person("Jane", "Smith", new DateTime(1990, 6, 20));
    var person3 = new Person("Alice", "Johnson", new DateTime(1985, 7, 30));
    var person4 = new Person("Bob", "Williams", new DateTime(2000, 8, 15));
    var person5 = new Person("Charlie", "Brown", new DateTime(1995, 9, 25));

    State.Persons = new [] { person1, person2, person3, person4, person5 };
    base.OnMounted();
}

public override VisualNode Render()
{
    return ContentPage(
        CollectionView()
            .ItemsSource(State.Persons, RenderPerson)
    );
}

private VisualNode RenderPerson(Person person)
{
    return VStack(spacing: 5,
        Label($"{person.FirstName} {person.LastName}"),
        Label(person.DateOfBirth.ToShortDateString())
            .FontSize(12)
            .TextColor(Colors.Gray)
    )
    .Margin(5,10);
}

CollectionView
ListView
https://learn.microsoft.com/en-us/dotnet/maui/user-interface/controls/collectionview/
https://github.com/adospace/mauireactor-samples/tree/main/Controls/CollectionViewTestApp
CollectionView showing some data