Skip to content

ListView is not virtualizing items #46

Closed

Description

@zbigniew-gajewski

MainPage.xaml:

<Page x:Class="UnoTest.MainPage"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:local="using:UnoTest"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      mc:Ignorable="d">

    <Grid  Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>

        <Grid Background="LightBlue">
            <TextBlock x:Name="TextBlock"
                       Margin="20"
                       FontSize="50"
                       VerticalAlignment="Center"
                       HorizontalAlignment="Center"
                       Text="{Binding NumberOfClicks}" />
        </Grid>

        <Button Grid.Row="1"
                Grid.ColumnSpan="2"
                FontSize="35"
                Foreground="White"
                Background="Green"
                Content="Click Me !"
                VerticalAlignment="Center"
                HorizontalAlignment="Center"
                Command="{Binding ClickMeButtonCommand}" />

        <ListView Grid.Row="0"
                  Grid.Column="1"
                  Background="Blue"
                  HorizontalAlignment="Stretch"
                  VerticalAlignment="Stretch"
                  ItemsSource="{Binding Numbers}">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding}"
                               Foreground="White"
                               FontSize="20"
                               FontWeight="Bold" />
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

    </Grid>
</Page>

MainPage.xaml.cs:

using UnoTest.Shared.ViewModels;
using Windows.UI.Xaml.Controls;

namespace UnoTest
{
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            InitializeComponent();
            DataContext = new MainPageViewModel();
        }
    }
}

MainPageViewModel.cs:

using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Input;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;

namespace UnoTest.Shared.ViewModels
{

#if __WASM__
    [Bindable(true)]
#endif
    public class MainPageViewModel : ViewModelBase
    {
        private int numberOfClicks = 0;
        private ObservableCollection<int> numbers = new ObservableCollection<int>();

        public MainPageViewModel()
        {
            ClickMeButtonCommand = new RelayCommand(OnClickMeButton);          
        }

        public ICommand ClickMeButtonCommand { get; } 

        public int NumberOfClicks
        {
            get => numberOfClicks;
            set
            {
                numberOfClicks = value;
                RaisePropertyChanged(nameof(NumberOfClicks));
            }
        }

        public ObservableCollection<int> Numbers => numbers;
        
        private void OnClickMeButton()
        {
            NumberOfClicks += 1;
            Numbers.Add(NumberOfClicks);
        }
    }
}

Result:
Eeach click adds a new element (int number) to the list which takes more and more time. After about only 10 clicks (only ten numbers on the list) adding next element (next click) takes about 1-2 seconds.

Additionally FireFox console shows many errors:

wasmlistviewmonoerrors

wasmlistviewmonoerrors2

MvvmLight compiled to .Net Standard 2.0 has been used.

Activity

  1. jeromelaban commented on Jun 16, 2018

    @jeromelaban
    Member

    The ListView implementation in WASM is not virtualizing items at the moment, and is using a StackPanel. The iOS and Android do virtualize properly, though.

  2. changed the title [-]Wasm and ListView - adding a couple of int elements to the list slower and slower[/-] [+][WASM] ListView is not virtualizing items[/+] on Jun 16, 2018
  3. added
    kind/bug
    platform/wasm 🌐
    on Jun 16, 2018
  4. changed the title [-][WASM] ListView is not virtualizing items[/-] [+]ListView is not virtualizing items[/+] on Jun 16, 2018
  5. added a commit that references this issue on Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugplatform/wasm 🌐

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions