Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ItemsRepeater inside of Viewbox leads to invisible items #15

Open
jangernert opened this issue Oct 20, 2022 · 2 comments
Open

ItemsRepeater inside of Viewbox leads to invisible items #15

jangernert opened this issue Oct 20, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@jangernert
Copy link

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
@jangernert jangernert added the bug Something isn't working label Oct 20, 2022
@timunie
Copy link

timunie commented Oct 20, 2022

I think ItemsRepeater is made for being placed inside a scrollviewer. While this still may be a bug, you may want to try ItemsControl instead. I wonder if it has the same bug or not.

@jangernert
Copy link
Author

@timunie thanks, ItemsControl works as expected.

I always use ItemsRepeater out of habit.

ItemsControl and ItemsRepeater both enable customizable collection experiences, but ItemsRepeater supports virtualizing UI layouts, while ItemsControl does not. We recommend using ItemsRepeater instead of ItemsControl, whether its for just presenting a few items from data or building a custom collection control.

https://learn.microsoft.com/en-us/windows/apps/design/controls/items-repeater

@maxkatz6 maxkatz6 transferred this issue from AvaloniaUI/Avalonia Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants