Giter VIP home page Giter VIP logo

avalonia.controls.itemsrepeater's People

Contributors

grokys avatar maxkatz6 avatar mrjul avatar robloo avatar simoncropp avatar wieslawsoltes avatar workgroupengineering avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

wieslawsoltes

avalonia.controls.itemsrepeater's Issues

ItemsRepeater Becomes Desynchronized With Items After Item Sort

Description
When using an ItemsRepeater control, the displayed items become out of sync with the items source after the items source is sorted. Display order is not respected, and other weird things can happen as well, including repeated visual elements which are not duplicated in the items source.

To Reproduce
The problem has persisted for me under a variety of circumstances. I have tried the following to fix the problem:

  • Scenario 1: When using ObservableCollection, I sort the items source using only the Move() method.

  • Scenario 2: When using ObservableCollection, I sort the items source in a temporary copy, then Clear() the items source and Add() from the sorted copy.

  • Scenario 3: When using a OneWay binding from the items source to ItemsRepeater.Items, I sort the items source in a temporary copy, destroy the original, assign the sorted copy to the items source, and then raise a PropertyChanged event.

  • CURRENT WORKAROUND: When a sort is completed, I destroy the previous ItemsRepeater and create a new one with the sorted items.

Expected behavior
The displayed items should match the source items, in both number and order, at all times.

Desktop

  • OS: Windows 10 Enterprise
  • Version: 10.0.19043 Build 19043

Additional context
This is my first project with Avalonia, so please tell me if you think I am doing something incorrectly.

Problem with bringing items in to view in the Items Repeater.

There seems to be a problem with bring in to view calls for repeater items. This issue is related to repeater virtualization where item needs to be created and scrollbar position needs to be calculated before item can be brought in to view.

For this to work GetOrCreateElement was made public but usage of it is not relay user friendly and can cause some issues.
After call to GetOrCreateElement is made user will get new item but calling BringInToView will result in empty repeater viewport if user does not wait for layout pass to be finished.
This not only mean user is not quite sure when can BringInToView be called but also additional items can be added to repeaters source collection before layout pass is over and this can also lead to empty viewport.

So only option user has is to force layout update after GetOrCreateElement to make sure all is ready for BringInToView call.
I wonder if we can make BringInToView safer feature to use as I imagine bringing things in to view in the repeater is one of things users will need.

To demonstrate this I created small repository: https://github.com/igorstefus/AvaloniaRepeaterProblem/tree/master/RepeaterProblem

Nested ItemsRepeater in a ScrollViewer behaves weird

Describe the bug

See the screen recording.

ItemsControl does not have such issue.

To Reproduce

https://github.com/balthild/avalonia-itemsrepeater-issue

<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:vm="clr-namespace:itemsrepeaterissue.ViewModels;assembly=itemsrepeaterissue"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
        x:Class="itemsrepeaterissue.Views.MainWindow"
        Icon="/Assets/avalonia-logo.ico"
        Title="itemsrepeaterissue">

    <Design.DataContext>
        <vm:MainWindowViewModel />
    </Design.DataContext>

    <ScrollViewer HorizontalScrollBarVisibility="Disabled">
        <ItemsRepeater Items="{Binding ItemGroups}" Margin="24">
            <ItemsRepeater.Layout>
                <StackLayout Spacing="24" />
            </ItemsRepeater.Layout>

            <ItemsRepeater.ItemTemplate>
                <DataTemplate>
                    <StackPanel Spacing="8">
                        <StackPanel Name="GroupTitle" Orientation="Horizontal">
                            <TextBlock Text="{Binding Title}" FontSize="24" />
                        </StackPanel>

                        <ItemsRepeater Items="{Binding Items}">
                            <ItemsRepeater.Layout>
                                <UniformGridLayout MaximumRowsOrColumns="2"
                                                   MinColumnSpacing="12"
                                                   MinRowSpacing="12"
                                                   ItemsStretch="Fill" />
                            </ItemsRepeater.Layout>

                            <ItemsRepeater.ItemTemplate>
                                <DataTemplate>
                                    <Border Padding="12" Background="#EEEEEE">
                                        <StackPanel Spacing="6">
                                            <TextBlock Text="Item name:" />
                                            <TextBlock Text="{Binding}" />
                                        </StackPanel>
                                    </Border>
                                </DataTemplate>
                            </ItemsRepeater.ItemTemplate>
                        </ItemsRepeater>
                    </StackPanel>
                </DataTemplate>
            </ItemsRepeater.ItemTemplate>
        </ItemsRepeater>
    </ScrollViewer>

</Window>
using System.Collections.Generic;
using System.Linq;

namespace itemsrepeaterissue.ViewModels {
    public class MainWindowViewModel : ViewModelBase {
        public class ItemGroup {
            public string Title { get; }
            public IEnumerable<string> Items { get; }

            public ItemGroup(string title, IEnumerable<string> items) {
                Title = title;
                Items = items;
            }
        }

        public IEnumerable<ItemGroup> ItemGroups =>
            new[] { 20, 20, 5, 2, 2, 2 }.Select(n => {
                return new ItemGroup(
                    $"Group with {n} items",
                    Enumerable.Range(0, n).Select(i => $"Item {i}")
                );
            });
    }
}

Desktop (please complete the following information):

  • OS: Windows 10 (20H2, 19042.685)
  • Version 0.10.0-rc1

ItemsRepeater's child not found in its Children collection exception

Describe the bug
ItemsRepeater using UniformGridLayout with 9 or more children gives the exception when you scroll it back and forth. It seems like ItemsRepeater does not load all the binded items together and unloads items that are unreachable by the user which might cause this kind of problems. It unloads the first item in my collection when I scroll to the bottom (you can see it in Avalonia DevTools) and does not load it back, leaving just blank space and crashing after I attempt to scroll again.

To Reproduce
Steps to reproduce the behavior:

  1. Create a random UserControl with the size of 244x226 and margins 0 20 19 0 (a Panel with random background should work)
  2. Create a ViewModel that has an AvaloniaList<UserControl> to bind ItemsRepeater to
  3. In this ViewModel constructor, add 10 or more UserControl to the AvaloniaList
  4. Create a ScrollViewer with the size of 572x510, put ItemsRepeater with UniformGridLayout inside of it and bind it to the AvaloniaList
  5. Run and scroll to the bottom and back - the first element should disappear, and scrolling back to the bottom crashes the app with System.InvalidOperationException: 'ItemsRepeater's child not found in its Children collection.'

Expected behavior
Scrolling should not make the 0th item in the collection disappear and crash the app.

Desktop (please complete the following information):

  • OS: Windows 10 Pro 21H2
  • Version 0.10.7

Additional context
I saw the same problems with XML in microsoft/microsoft-ui-xaml#2969 and microsoft/microsoft-ui-xaml#2834. Maybe that could help.

Enabling WrapLayout in ControlCatalog crashes the app

Describe the bug
Code behind for ItemsRepeater page in the ControlCatalog supports switching to WrapLayout. Somehow we lost XAML part that was actually listing this layout. But if you enable it, it will crash anyway.

To Reproduce
Steps to reproduce the behavior:

  1. Apply this patch: enable-wrap-layout.txt
  2. Go to "ItemsRepeater" page
  3. Change layout to "Wrap - Vertical"
  4. Wait for a minute or two
  5. App crashes due to invalid layout

Expected behavior
No crashes due to WrapLayout asking to be given all the space in universe.

Screenshots

Desktop (please complete the following information):

  • OS: Windows 10
  • Version: master

ItemsRepeater inside of Viewbox leads to invisible items

When a ItemsRepeater is inside a Viewbox the list of shown items doesn't take the Viewbox transformation into account (or at least not correctly). Not all of the items are drawn even though there is enough space due to the Viewbox.

To Reproduce
Minimal sample:

<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:vm="using:avalonia_showcase.ViewModels"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        x:Class="avalonia_showcase.Views.MainWindow"
        Icon="/Assets/avalonia-logo.ico"
        Width="300"
        Height="200"
        Title="avalonia_showcase">

    <Design.DataContext>
        <vm:MainWindowViewModel/>
    </Design.DataContext>
    <Grid RowDefinitions="*,30" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">

        <Viewbox Grid.Row="0" Stretch="Uniform" StretchDirection="DownOnly">
            <ItemsRepeater Items="{Binding Items}" >
                <ItemsRepeater.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding}" Padding="5"/>
                    </DataTemplate>
                </ItemsRepeater.ItemTemplate>
            </ItemsRepeater>
        </Viewbox>

        <Button Command="{Binding Add}" Content="Add" Grid.Row="1" HorizontalAlignment="Center"/>
    </Grid>
</Window>

The viewmodel is simply a ObservableCollection to which strings can be added with via the button:

using System.Collections.ObjectModel;

namespace avalonia_showcase.ViewModels
{
    public class MainWindowViewModel : ViewModelBase
    {
        public ObservableCollection<string> Items { get; } = new ObservableCollection<string>();

        public MainWindowViewModel()
        {
            Items.Add("abc");
            Items.Add("def");
        }
        

        public void Add()
        {
            Items.Add("test 123");
        }
    }
}

Expected behavior
Since the whole ItemsRepeater is shrunken down to fit all of its content, I'd expect all of it to be visible.

Screenshots
Screencast from 2022-10-20 16-57-31 (trimmed).webm

Desktop (please complete the following information):

  • OS: both windows 10 and Fedora 37
  • Version 0.10.18

ItemsRepeater shows the wrong item location when the data volume is large

Describe the bug
ItemsRepeater shows the wrong item location when the data is large
image

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. Windows, Mac, Linux (State distribution)]
  • Version [e.g. 0.10.0-rc1 or 0.9.12]

Additional context
Add any other context about the problem here.

DataTemplate adaptation is wrong in ItemsRepeater

Describe the bug

DataTemplate adaptation is wrong in ItemsRepeater.

Reproduction project

https://github.com/YoshihiroIto/AvaloniaDataTemplateProblem

This project works as follows
Numbers below 100 are displayed in red.
Numbers above 100 are displayed in green.
When the Add Items button is clicked, 10 items are added.
When the Remove Items button is clicked, 10 items are removed.

        <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled">
            <ItemsRepeater Items="{Binding Items}">
                <ItemsRepeater.Layout>
                    <UniformGridLayout MinItemWidth="60" Orientation="Vertical" />
                </ItemsRepeater.Layout>

                <ItemsRepeater.ItemTemplate>
                    <views:DataTemplateSelector>
                        <views:DataTemplateSelector.Under100DataTemplate>
                            <DataTemplate DataType="viewModels:DataViewModel">
                                <TextBlock
                                    Width="60"
                                    Foreground="Red"
                                    Text="{Binding Index}" />
                            </DataTemplate>
                        </views:DataTemplateSelector.Under100DataTemplate>

                        <views:DataTemplateSelector.Over100DataTemplate>
                            <DataTemplate DataType="viewModels:DataViewModel">
                                <TextBlock
                                    Width="60"
                                    Foreground="Green"
                                    Text="{Binding Index}" />
                            </DataTemplate>
                        </views:DataTemplateSelector.Over100DataTemplate>
                    </views:DataTemplateSelector>
                </ItemsRepeater.ItemTemplate>
            </ItemsRepeater>
        </ScrollViewer>
    public class DataTemplateSelector : IDataTemplate
    {
        public IDataTemplate? Over100DataTemplate { get; set; }
        public IDataTemplate? Under100DataTemplate { get; set; }

        public IControl? Build(object? param)
        {
            if (param is not DataViewModel vm)
                throw new NotSupportedException();

            return vm.IsOver100
                ? Over100DataTemplate?.Build(param)
                : Under100DataTemplate?.Build(param);
        }

        public bool Match(object? data)
        {
            return data is DataViewModel;
        }
    }
    public class MainViewModel : ViewModelBase
    {
        public ObservableCollection<DataViewModel> Items { get; } = new();

        public ReactiveCommand<Unit, Unit> AddItemsCommand { get; }
        public ReactiveCommand<Unit, Unit> RemoveItemsCommand { get; }

        public MainViewModel()
        {
            for (var i = 0; i != 200; ++i)
                Items.Add(new DataViewModel { Index = Items.Count });

            AddItemsCommand = ReactiveCommand.Create(() =>
                {
                    for (var i = 0; i != 10; ++i)
                        Items.Add(new DataViewModel { Index = Items.Count });
                }
            );

            RemoveItemsCommand = ReactiveCommand.Create(() =>
                {
                    for (var i = 0; i != 10; ++i)
                        Items.RemoveAt(Items.Count - 1);
                }
            );
        }
    }

    public class DataViewModel : ViewModelBase
    {
        public int Index
        {
            set
            {
                this.RaiseAndSetIfChanged(ref index, value);
                this.RaisePropertyChanged(nameof(IsOver100));
                this.RaisePropertyChanged(nameof(IsUnder100));
            }

            get => index;
        }

        public int index;

        public bool IsOver100 => Index > 100;
        public bool IsUnder100 => !IsOver100;
    }

To Reproduce

After adding and deleting items several times, the colors are displayed incorrectly.

Expected behavior

After repeated addition and deletion of items, below 100 are displayed in red, and above 100 are displayed in green.

Screenshots

2022-09-16-21-00-37.mp4

Desktop

OS: Windows 11
Avalonia: 11.0.0-preview1

ItemsRepeater has incorrect render result when scroll back to previous contents

Describe the bug

Some text will disappear when scrolling back to the previous elements in ItemsRepeater

To Reproduce

  1. Create an ItemsRepeater with ItemTemplate.
  2. Scroll up and down to see items disappear

Expected behavior

  1. Elements should be the same when scrolling up and down

Screenshots

record

Desktop (please complete the following information):

  • OS: Windows 11 22H2
  • Version: Avalonia Latest Nightly Build

ItemsRepeater not updating correctly after remove items from ObservableList

Describe the bug

I have a personal app that uses ItemsRepeater to list multiple tv shows data. Before updating to Avalonia 11.0.10 everything was working fine regarding removing items from an observable list and the item updating in ItemsRepeater.
I'm also using CommunitToolkit.MVVM.

After the update to 11.0.10 the ItemsRepeater, apparently, loses context the item context and shows the content as it is not loaded.
When I resized the screen "refreshes" and everything item came back to normal.

This project run in windows and android, but the issue only happens in Windows.

So before came here I tried to replicate the issue, with a similar approach I was using a smaller sample project, but I couldn't replicate the issue.

To Reproduce

So the project where the error happens is: (it's kinda big, idk if would help) https://github.com/adleywd/WhatsNextSeries/tree/feature/MigrateToDotNetAvalonia/src/WhatsNextSeries

The sample I tried to reproduce it (but I couldn't yet)
https://github.com/adleywd/AvaloniaItemsRepeaterSample

Expected behavior

When an item is removed from an observable list, the ItemsRepeater should remove the item but keep the context of unmodified items.

Avalonia version
11.0.10

OS
Windows

Additional context
With the bug in Avalonia 11.0.10
After removing and item from the list, other Items go back to default value:
"Tv show name"
"Not available"

11 0 10

With Avalonia 11.0.7
11 0 7

Keyboard navigation issues when using ItemsRepeater

Describe the bug

In the provided sample, I'm using an ItemsRepeater and a nested ItemsRepeater to create multiple toggle buttons. The sample also has 2 toggle buttons created in XAML directly. Tabbing through the items allows me to tab through the XAML generated toggle buttons until I reach the first toggle button created by the ItemsRepeater. I can't tab to the other items.

Some additional observations:

  • The menu in the provided sample is also included when cycling through the controls using the tab key. Although only the first item is highlighted with the white focus adorner. I can use the cursor keys in the menu but it doesn't really move the white focus adorner to the item.
  • I can use keyboard accelerators (if unique) to move/toggle a specific toggle button but when duplicate accelerators are in place, I can't cycle through those by repeatedly hit the accelerator. There are already open issues:
    AvaloniaUI/Avalonia#7090
    AvaloniaUI/Avalonia#13160

To Reproduce

A simple repro case can be found here:
https://github.com/StefanKoell/Misc/tree/main/src/AvaTabKeyIssue

  1. Start the app
  2. Hit the tab keys to cycle through the items
  3. Note that I can't reach items beyond the first one in the items repeater.

Expected behavior

When tabbing through the UI, I expect that all controls (with IsTabStop set to true) show the white focus adorner to allow keyboard interaction. I would also expect to cycle through all the items and show the white focus adorner using the accelerator key when multiple identical keys are assigned.

Environment

  • OS: Windows 11
  • .NET 8
  • Avalonia-Version: 11.0.6

WrapLayout caching incorrect when source collection is changed

Description
WrapLayout is not updating correctly when source collection is changed.

Consider an ItemsRepeater bound to a changing source collection "CurrentNode.Things".
With <UniformGridLayout /> the ItemsRepeater displays the correct items from "CurrentNode.Things" as CurrentNode changes.

If I change to <WrapLayout />, the number of displayed items updates correctly, but any items from the previous source are displayed instead.

In the example below, the UniformGridLayout is left, and WrapLayout on the right...
WrapLayout

To Reproduce

    public class Thing
    {
        public string? Name { get; set; }
    }

    public class FolderNode
    {
        public ObservableCollection<Thing> Things { get; set; } = new ObservableCollection<Thing>();

        public FolderNode(List<string> Names)
        {
            foreach (string c in Names)
            {
                Things.Add(new Thing { Name = c });
            }
        }
    }
    public class MainWindowViewModel : ViewModelBase
    {
        private FolderNode _currentNode = default!;
        public FolderNode CurrentNode
        {
            get => _currentNode;
            set
            {
                this.RaiseAndSetIfChanged(ref _currentNode, value);
            }
        }

        ObservableCollection<FolderNode> Folders { get; set; } = new ObservableCollection<FolderNode>();

        public ICommand SelectFolderCommand { get; }

        public MainWindowViewModel()
        {
            Folders.Add(new FolderNode(new List<string>()));
            Folders.Add(new FolderNode(new List<string>() { "A", "B" }));
            Folders.Add(new FolderNode(new List<string>() { "D", "E", "F" }));

            CurrentNode = Folders[0];

            SelectFolderCommand = ReactiveCommand.Create<string>(param =>
            {
                CurrentNode = Folders[int.Parse(param)];
            });
        }
    }
  <Grid ColumnDefinitions="Auto,1*,1*">

    <StackPanel Grid.Column="0">
      <Button Command="{Binding Path=SelectFolderCommand}" CommandParameter="0">0</Button>
      <Button Command="{Binding Path=SelectFolderCommand}" CommandParameter="1">2</Button>
      <Button Command="{Binding Path=SelectFolderCommand}" CommandParameter="2">3</Button>
    </StackPanel>

    <ItemsRepeater Grid.Column="1" Items="{Binding Path=CurrentNode.Things}" Background="Bisque">
      <ItemsRepeater.ItemTemplate>
        <DataTemplate>
          <TextBox Text="{Binding Path=Name}" HorizontalAlignment="Left" />
        </DataTemplate>
      </ItemsRepeater.ItemTemplate>
      <ItemsRepeater.Layout>
        <UniformGridLayout />
      </ItemsRepeater.Layout>
    </ItemsRepeater>

    <ItemsRepeater Grid.Column="2" Items="{Binding Path=CurrentNode.Things}" Background="AliceBlue">
      <ItemsRepeater.ItemTemplate>
        <DataTemplate>
          <TextBox Text="{Binding Path=Name}" />
        </DataTemplate>
      </ItemsRepeater.ItemTemplate>
      <ItemsRepeater.Layout>
        <WrapLayout />
      </ItemsRepeater.Layout>
    </ItemsRepeater>

  </Grid>

Expected behavior
WrapLayout should display the correct items from source!

Desktop:

  • OS: Windows 10 Pro
  • Version 2004 (19041.928)
  • Avalonia 0.10.3

ItemsRepeater behaves erratically when adding items to front of list

https://github.com/mike-ward/demoscroll

DemoScroll is a minimal Avalonia desktop application that demonstrates undesirable scrolling behavior.

What it does:

  • Constructs a window that contains an ItemsRepeater
  • Fills a list with sample text that is bound to the ItemsRepeater.
  • Starts a 2 second timer and inserts sample text to the front of the list.

What it demonstrates:

  • Text will start disappearing the moment new text is added by the timer.
  • Grab the scrollbar thumb and move up and down. Application will stop drawing and otherwise behave erratically.

Desktop (please complete the following information):

  • OS: Microsoft Windows [Version 10.0.19042.746]
  • Version 0.10

Additional context
Related to AvaloniaUI/Avalonia#5151

Nested ItemsRepeater issues

Describe the bug
When nesting ItemsRepeaters, a couple things...
1- When scrolling, primarily with the scrollbar thumb, the garbage collector runs almost constantly. I can't tell if this occurs in WinUI since that mostly lives in native memory

2- When scrolling, especially large jumps quickly, the scrollviewer will freeze. Resizing a parent container (like the window) will fix it. I think this is related to the items of different height issue, but I haven't seen any reports of freezing yet. I also can't replicate this in WinUI, I can get choppy scrolling but it never fully freezes. Sometimes it takes aggressive scrolling to cause this (like in the video I attached), and sometimes one large quick scroll will do it.

(see attached video for demo of 1 & 2)

3- There may or may not be a memory leak. I do think this also occurs upstream in WinUI, as process memory slowly climbs when scrolling.
When first loaded, 10 ListBoxItems are present
Scroll up and down the list once: 179 ListBoxItems are present
Scroll randomly: 301
Scrolling some more: 438

To Reproduce
Example code:
Group installed fonts alphabetically and display using nested ItemsRepeaters

public class ViewModel
{
        public ViewModel()
        {
	        Items = new List<string>(FontManager.Current.GetInstalledFontFamilyNames());
	        var query = from item in Items
				        group item by item.Substring(0, 1).ToUpper() into g
				        orderby g.Key
				        select new GroupInfo(g) { Key = g.Key };
	        Groups = new List<GroupInfo>(query);
        }

        public List<string> Items { get; }
        public List<GroupInfo> Groups { get; }
}

public class GroupInfo : List<string>
{
        public string Key { get; set; }
        public GroupInfo(IEnumerable<string> items) : base(items) { }
}

Window Content:

<Panel>
      <Border Width="350" Height="400"
              BorderBrush="{DynamicResource SystemControlHighlightBaseLowBrush}"
              BorderThickness="1">
          <ScrollViewer HorizontalScrollBarVisibility="Disabled">
              <ItemsRepeater Items="{Binding Groups}">
                  <ItemsRepeater.ItemTemplate>
                      <DataTemplate>
                          <StackPanel>
                              <Border Height="40">
                                  <TextBlock Text="{Binding Key}"
                                             VerticalAlignment="Center"
                                             Margin="12 0"
                                             FontWeight="Bold"/>
                              </Border>
                              <ItemsRepeater Items="{Binding}">
                                  <ItemsRepeater.ItemTemplate>
                                      <DataTemplate>
                                          <ListBoxItem Height="40" Content="{Binding}" />
                                      </DataTemplate>
                                  </ItemsRepeater.ItemTemplate>
                              </ItemsRepeater>
                          </StackPanel>
                      </DataTemplate>
                  </ItemsRepeater.ItemTemplate>
              </ItemsRepeater>
          </ScrollViewer>
      </Border>
  </Panel>

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
https://user-images.githubusercontent.com/40413319/111887602-0ebf6c00-89a4-11eb-80c9-889c42d62ce5.mp4

Desktop (please complete the following information):

  • OS: Windows 10
  • Version 0.10

Segmentation Fault when Using an ItemsRepeater in a Scrollviewer

Describe the bug
On Debian Buster, when you use an ItemsRepeater inside of a ScrollViewer and start to scroll after a little while you get a segmentation fault error. This only occurs when using .net 6.

To Reproduce
Steps to reproduce the behavior:

  1. Go to Example Repository
  2. Download and run the code
  3. Scroll down until crash (should occur quickly)
  4. See error on terminal

Expected behavior
Ability to keep scrolling down and view all data without crashing.

Screenshots
No screenshots.

Desktop (please complete the following information):

  • OS: Linux - Debian Buster
  • Version 10.11

Additional context
Does not occur on windows 10. Using the .net 5 sdk lets the program run normally as expected

`ItemsRepeater` inside `ScrollViewer`, DataContext inconsistencies

Describe the bug
Using the ItemsRepeater inside ScrollViewer causes inconsistencies with DataContext.
When I scroll to the end of the ScrollViewer, or close to, the first few items' DataContext becomes null,
and when going back up, it may get mixed around with other objects.

To Reproduce

Steps to reproduce the behavior:

  1. Have a ItemsRepeater control inside ScrollViewer and populate
  2. Populate the ItemsRepeater
  3. Scroll down the ScrollViewer far enough
  4. Monitor the DataContext of ItemsRepeater

Expected behavior

DataContext is supposed to not become null, or get jumbled around.

Screenshots

bug_case.mp4

Desktop (please complete the following information):

  • OS: Windows 11 22H2
  • Version Avalonia 11.0.4

Additional context

Bug case minimal reproducible example
bug_case.zip

Item Repeater WrapLayout Throws

Describe the bug

I have a grid of 2 columns and a grid splitter. The second column has an item repeater of borders. When resizing with the grid splitter the app throws a null exception.
ItemRepeaterBug.zip

To Reproduce

`

	<!-- GridSplitter for resizing -->
	<GridSplitter Grid.Column="1" Width="5" HorizontalAlignment="Center" VerticalAlignment="Stretch" />

	<!-- ItemsRepeater in the Second Column -->
	<ItemsRepeater Name="ItemsRepeater" ItemsSource="{Binding Skills}" Grid.Column="2">
		<ItemsRepeater.Layout>
			<WrapLayout
				Orientation="Horizontal"
				VerticalSpacing="15"
				HorizontalSpacing="15" />
		</ItemsRepeater.Layout>
		<ItemsRepeater.ItemTemplate>
			<DataTemplate>
				<Border BorderBrush="Black"
						BorderThickness="2"
						Background="{DynamicResource ArWhite}"
						Height="80"
						Width="70">
				</Border>
			</DataTemplate>
		</ItemsRepeater.ItemTemplate>
	</ItemsRepeater>
</Grid>`
` public partial class MainViewModel : ViewModelBase
        {
            public ObservableCollection<int> Skills { get; } = new ObservableCollection<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
        }`

Expected behavior

No response

Avalonia version

11.0.10

OS

Windows

Additional context

No response

ItemsRepeater in ScrollViewer - scroll resets to 0 on app lags when scrolling

Describe the bug
Your app slightly lags and you have an ItemsRepeater in a ScrollViewer. When you start scrolling down - there is a big chance of scroll resetting to 0 position.

To Reproduce
Steps to reproduce the behavior:

Sorry for not providing an example project with a repro - it's a lot of time to emulate this conditions.

  1. Launch lunacy 8.1 https://docs.icons8.com/release-notes/#81
  2. Unzip and open attached file in Lunacy 081221 scroll tree.sketch.zip
  3. rename two elements
  4. scroll down
  5. repeat from step 3

Expected behavior
Scroll do not resets to 0 position.

Screenshots
We've attached a video

Desktop (please complete the following information):

  • We have repro on any desktop platform

Additional context
I've debugged deep. The bug is based on two behaviors:

  1. ItemsRepeater recycles elements by setting them position of another element, or -10k position if there is nothing to recycle.
  2. ScrollContentPresenter saves the link to the anchor element and calculates everything from it. see TrackAnchor local method.
  3. There is a chance that anchor element gets recycled by ItemsRepeater
  4. Position of element jumps to other elements position or -10k if hidden, so offset of ScrollViewer tries to set equally in invalid or even negative area.
  5. Coerce logic resets negative value to zero offset on negative value. Or scroll just jumps to other position.

So to fix this I think ScrollContentPresenter should check for anchor getting recycled.

I've temporarily fixed this by a hack in our app: If scroll is resets to zero without any point - I'm restoring old offset.

ItemsRepeater extremely slow

Describe the bug
Even with ~20 items, ItemsRepeater takes a few seconds to scroll.

To Reproduce

    <DockPanel>
        <TextBox
            Name="SearchTextBox"
            Margin="15,5,15,10"
            Classes="clearButton"
            DockPanel.Dock="Top"
            Text="{Binding SearchTerm}"
            Watermark="Filter" />
        <ScrollViewer Padding="15,0">
            <ItemsRepeater ItemsSource="{Binding Types}">
                <ItemsRepeater.ItemTemplate>
                    <DataTemplate DataType="model:TypeExtract">
                        <controls:SettingsExpander
                            Margin="0,1"
                            Description="{Binding Namespace}"
                            Header="{Binding Name}" />
                    </DataTemplate>
                </ItemsRepeater.ItemTemplate>
            </ItemsRepeater>
        </ScrollViewer>
    </DockPanel>

Desktop (please complete the following information):

  • OS: Windows 11
  • Version 11.0.1

Additional context
Debug output constantly shows

[Layout]Layout cycle detected. Item 'Avalonia.Controls.StackPanel' was enqueued '10' times.(LayoutQueue`1 #12819582)
[Layout]Layout cycle detected. Item 'Avalonia.Controls.TextBlock' was enqueued '10' times.(LayoutQueue`1 #12819582)
[Layout]Layout cycle detected. Item 'Avalonia.Controls.Presenters.ContentPresenter' was enqueued '10' times.(LayoutQueue`1 #12819582)

ItemsRepeater doesn't show items after maximizing window

Describe the bug
When I have some items collection rendered using ItemsRepeater nested in ScrollView, and it's not visible due to being too low in the ScrollView, it does not render items after becoming visible when maximizing window.

If I do resize the window using window side handler, it does show up as expected.

To Reproduce

  1. Run the attached repro project:
    Report.zip
  2. Maximize window.
  3. See no white rectangles appear at the bottom of the screen.
  4. Now restore window and maximize it again.
  5. See items are visible now.

Expected behavior
I expect to see items right away after first window maximize.

Screenshots
Reproduction video:
https://user-images.githubusercontent.com/883587/202908113-89d0327c-1334-4bf7-b85f-9ea19d2807b9.mp4

Desktop (please complete the following information):

  • OS: Win 11 22H2
  • Version 11.0.0-preview.4

Additional context
I'm using 125% UI scaling and 2K display.

[11 Nightly] :nth-last-child(1) Only evaluated once at runtime

Discussed in AvaloniaUI/Avalonia#12147

Originally posted by Mrcubix July 11, 2023
For some reasons, the selector :nth-last-child(1) seems to only be evaluated properly at first, any additions done after the Window is shown will result in an incorrect behavior.

in this exemple, the last element is supposed to have a margin of 0, so that the scrollbar doesn't show up until another element is added.

the same behavior can be obtained using this repo: https://github.com/Mrcubix/Avalonia-Last-Nth-Child-Selector-Issue

Note that the orginal discussion was written in an earlier version, but the issue is still valid to this day

Avalonia bug where the ItemsRepeater control only evaluates the nth-last-child(1) selector at initial render

about the same styling works for ItemsControl, however, ItemsControl suffer from a worse issue explained here #12137

ItemsRepeater poor performance with nested items repeaters

Describe the bug
ItemsRepeater have poor performance when it contains nested items repeaters.

video.mp4

There are also performance issues on large plain lists with emoji.

video2.mp4

These videos are recorded in Release configuration (dotnet run -c Release).
Here is my workstation configuration:
image

To Reproduce
demo.zip

Desktop (please complete the following information):

  • OS: MacOS 12.6
  • Version 11.0.0-preview2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.