Open Hunv opened 1 month ago
FYI: ItemsRepeater is being deprecated soonish. It is however still somewhat supported right now.
https://github.com/AvaloniaUI/Avalonia.Controls.ItemsRepeater
FYI: ItemsRepeater is being deprecated soonish. It is however still somewhat supported right now.
https://github.com/AvaloniaUI/Avalonia.Controls.ItemsRepeater
I wasn't aware that the ItemsRepeater
is deprecated.
OK, thank you for the hint. On the first view ItemsControl
can be used as a drop-in replacement for the ItemsRepeater
in this case. This also seems to fix the issue.
But it seems that the ItemsControl
is much slower than the ItemsRepeater
if the list is longer (i.e. 1000 items).
I wasn't aware that the ItemsRepeater is deprecated.
It's not yet. It will be sometime after 12.0 releases though (no idea when that is). I will say you should still avoid using it for new developments though. But fixes and bug reports are technically still being accepted for it.
But it seems that the ItemsControl is much slower than the ItemsRepeater if the list is longer (i.e. 1000 items).
Do you have virtualisation enabled? The majority of ItemsRepeater panels are virtualised. ItemsControl however is not virtualised by default.
If you change ItemsPanel
on the ItemsControl
to a VirtualizingStackPanel
it will probably fix your issue.
Thank you very much for that hint. This replaces the ItemsRepeater completely - at least for me:
<ScrollViewer
ScrollViewer.VerticalScrollBarVisibility="Auto"
>
<ItemsControl
ItemsSource="{Binding MyItemList}"
>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="vm:MyModel">
<Border>
...
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</ScrollViewer>
Glad I could help
Describe the bug
I have this:
The.
When I add a new Item to the Top of the list via
MyItemList
is an ObservableCollectionMyItemList.Insert(0, ...)
and run athis.RaisePropertyChanged(nameof(MyItemList));
, the space of the new item in theItemsRepeater
is used but the item itself is not rendered. This does not happen from the very beginning but after some (not so long) time. I think shortly after when the first items runs out of the visible part of the Window. If I scroll just a pixel in theScrollViewer
, everything is where and how it should be immediately. This does not happen, if theScrollViewer
is not involved.This is how it looks like:
To Reproduce
Create a new Avalonia Project from scratch with Desktop enabled. Leave everything else at default. Make the following changes:
Avalonia.ItemsRepeater
Nuget to the main projectMainViewModel.cs
with this:namespace AvaloniaApplication1.ViewModels;
public class MainViewModel : ViewModelBase { public ObservableCollection MyItemList { get; set; } = new ObservableCollection();
private readonly System.Timers.Timer _TmrDisruptionUpdate = new(1000);
}
namespace AvaloniaApplication1.ViewModels { public class MyModel { public string Text { get; set; } } }
<UserControl xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:vm="clr-namespace:AvaloniaApplication1.ViewModels" xmlns:cntrl="using:Avalonia.Controls" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="AvaloniaApplication1.Views.MainView" x:DataType="vm:MainViewModel">
<ScrollViewer ScrollViewer.VerticalScrollBarVisibility="Auto"
Expected behavior
Also later added items are rendered as the first items that were added.
Avalonia version
11.1.4
OS
Windows
Additional context
No response