Search code examples
c#maui.net-7.0

.NET MAUI: Scrollable list of log data


I'm making an application for gathering serial communication data and presenting it in a log window. This is my first .NET MAUI application, and I'm having problems with finding a way that performs well.

Preferably I would like to have columns with timestamp, raw hex bytes and ascii strings. But using a ListView with a Grid for each line with perhaps a couple hundred lines is not performing very well even on my Macbook M1 Max. It's really sluggish and completely unusable.

<ListView
    ItemsSource="{Binding ReceivedDataBuffer}"
    ios:ListView.RowAnimationsEnabled="False"
    HasUnevenRows="False"
    CachingStrategy="RetainElement">
    <ListView.ItemTemplate>
        <DataTemplate x:DataType="vm:ReceivedData">
            <ViewCell>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Label Grid.Column="0"
                            Text="{Binding Timestamp}"
                            FontAttributes="Bold" />
                    <Label Grid.Column="1"
                            Text="{Binding HexString}"
                            FontAttributes="Italic"/>
                </Grid>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

Is there a way to get the ListView to perform better? Or is there a control that's better suited to show a lot of logged data (approx. 10,000 lines) with multiple properties?


Solution

  • You can use the DataGrid instead of ListView if you want to perform well. As the DataGrid can show different data types in different types of columns and it will only load what you scroll to.

    I use the code below to show 10,000 lines of pseudo data in DataGrid and it performs well.

    for(int i = 0; i<10000; i++)
    {
          orderInfo.Add(new OrderInfo("testdata column"+i, "testdata column" + i, "testdata column" + i, "testdata column" + i, "testdata column" + i));
    }
    
    

    And you can refer to DataGrid in .NET MAUI on how to use it.