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

Scrolling in ListBox causes stack overflow exception #2936

Closed
DarkSideOfDay opened this issue Sep 6, 2019 · 5 comments · Fixed by #9677
Closed

Scrolling in ListBox causes stack overflow exception #2936

DarkSideOfDay opened this issue Sep 6, 2019 · 5 comments · Fixed by #9677
Labels

Comments

@DarkSideOfDay
Copy link

Repro steps:

  1. Create a new Avalonia app.
  2. Replace the InitializeComponent function with the following:
        private void InitializeComponent()
        {
            AvaloniaXamlLoader.Load(this);

            var listBox = new ListBox();
            listBox.Background = Brushes.White;
            listBox.BorderThickness = new Thickness(0);

            List<string> list = new List<string>();
            for (int i = 0; i < 150; i++)
            {
                list.Add("test|4.50|asdfasdfasdf");
            }

            List<ListBoxItem> items = new List<ListBoxItem>();
            foreach (string txt in list)
            {
                ListBoxItem lbi = new ListBoxItem { Content = new TextBlock { Text = txt } };
                lbi.Cursor = new Cursor(StandardCursorType.Hand);
                lbi.Height = 40;
                lbi.FontSize = 13;
                lbi.VerticalContentAlignment = Avalonia.Layout.VerticalAlignment.Center;
                items.Add(lbi);
            }
            listBox.Items = items;
            if (listBox.ItemCount > 0) listBox.SelectedIndex = 0;
            Content = listBox;
        }
  1. Run the app, scroll all the way down then all the way back up. Stack overflow exception occurs when scrollbar is close to the top.
@FoggyFinder
Copy link
Contributor

Version of Avalonia?

@DarkSideOfDay
Copy link
Author

Tested on both 0.8.2 and the nightly build.

@grokys grokys added the bug label Sep 9, 2019
@CreateLab
Copy link
Contributor

CreateLab commented Sep 30, 2019

reproduce this bug with just xaml

  <ListBox ScrollViewer.VerticalScrollBarVisibility="Visible">
        <ListBoxItem>
            <StackPanel>
                <TextBlock  Text="A single character of: a, b or c" />
                <TextBlock Classes="green" Text="[abc]" />
            </StackPanel>
        </ListBoxItem>
        <ListBoxItem>
            <StackPanel>
                <TextBlock Text="A character except: a, b or c" />
                <TextBlock Classes="green" Text="[^abc]" />
            </StackPanel>
        </ListBoxItem>
        <ListBoxItem>
            <StackPanel>
                <TextBlock Text="A character in the range: a-z" />
                <TextBlock Classes="green" Text="[a-z]" />
            </StackPanel>
        </ListBoxItem>
        <ListBoxItem>
            <StackPanel>
                <TextBlock Text="A character not in the range: a-z" />
                <TextBlock Classes="green" Text="[^a-z]" />
            </StackPanel>
        </ListBoxItem>
        <ListBoxItem>
            <StackPanel>
                <TextBlock Text="A character in the range: a-z or A-Z" />
                <TextBlock Classes="green" Text="[a-zA-Z]" />
            </StackPanel>
        </ListBoxItem>
        <ListBoxItem>
            <StackPanel>
                <TextBlock Text="Any single character" />
                <TextBlock Classes="green" Text="." />
            </StackPanel>
        </ListBoxItem>
        <ListBoxItem>
            <StackPanel>
                <TextBlock Text="Any whitespace character" />
                <TextBlock Classes="green" Text="\s" />
            </StackPanel>
        </ListBoxItem>
        <ListBoxItem>
            <StackPanel>
                <TextBlock Text="Any non-whitespace character" />
                <TextBlock Classes="green" Text="\S" />
            </StackPanel>
        </ListBoxItem>
        <ListBoxItem>
            <StackPanel>
                <TextBlock Text="Any digit" />
                <TextBlock Classes="green" Text="\d" />
            </StackPanel>
        </ListBoxItem>
        <ListBoxItem>
            <StackPanel>
                <TextBlock Text="Any non-digit" />
                <TextBlock Classes="green" Text="\D" />
            </StackPanel>
        </ListBoxItem>
        <ListBoxItem>
            <StackPanel>
                <TextBlock Text="Any word character" />
                <TextBlock Classes="green" Text="\w" />
            </StackPanel>
        </ListBoxItem>
        <ListBoxItem>
            <StackPanel>
                <TextBlock Text="Any non-word character" />
                <TextBlock Classes="green" Text="\W" />
            </StackPanel>
        </ListBoxItem>
        <ListBoxItem>
            <StackPanel>
                <TextBlock Text="Capture everything enclosed" />
                <TextBlock Classes="green" Text="(...)" />
            </StackPanel>
        </ListBoxItem>
        <ListBoxItem>
            <StackPanel>
                <TextBlock Text="Match either a or b" />
                <TextBlock Classes="green" Text="(a|b)" />
            </StackPanel>
        </ListBoxItem>
        <ListBoxItem>
            <StackPanel>
                <TextBlock Text="Zero or one of a" />
                <TextBlock Classes="green" Text="a?" />
            </StackPanel>
        </ListBoxItem>
        <ListBoxItem>
            <StackPanel>
                <TextBlock Text="Zero or more of a" />
                <TextBlock Classes="green" Text="a*" />
            </StackPanel>
        </ListBoxItem>
        <ListBoxItem>
            <StackPanel>
                <TextBlock Text="One or more of a" />
                <TextBlock Classes="green" Text="a+" />
            </StackPanel>
        </ListBoxItem>
        <ListBoxItem>
            <StackPanel>
                <TextBlock Text="Exactly 3 of a" />
                <TextBlock Classes="green" Text="a{3}" />
            </StackPanel>
        </ListBoxItem>
        <ListBoxItem>
            <StackPanel>
                <TextBlock Text="3 or more of a" />
                <TextBlock Classes="green" Text="a{3,}" />
            </StackPanel>
        </ListBoxItem>
        <ListBoxItem>
            <StackPanel>
                <TextBlock Text="Between 3 and 6 of a" />
                <TextBlock Classes="green" Text="a{3,6}" />
            </StackPanel>
        </ListBoxItem>
        <ListBoxItem>
            <StackPanel>
                <TextBlock Text="Start of string" />
                <TextBlock Classes="green" Text="^" />
            </StackPanel>
        </ListBoxItem>
        <ListBoxItem>
            <StackPanel>
                <TextBlock Text="End of string" />
                <TextBlock Classes="green" Text="$" />
            </StackPanel>
        </ListBoxItem>
        <ListBoxItem>
            <StackPanel>
                <TextBlock Text="A word boundary" />
                <TextBlock Classes="green" Text="\b" />
            </StackPanel>
        </ListBoxItem>
        <ListBoxItem>
            <StackPanel>
                <TextBlock Text="Non-word boundary" />
                <TextBlock Classes="green" Text="\B" />
            </StackPanel>
        </ListBoxItem>
    </ListBox>

@grokys
Copy link
Member

grokys commented Oct 1, 2019

Hi @stephenfournier @CreateLab yeah, ListBox is currently a bit broken when assigning ListBoxItems to a ListBox.Items property caused by our virtualization code.

I intend to rewrite our listbox virtualization code in 0.10 (see #2594) but for the meantime, the best fox for this is to set VirtualizationMode="None" on your listbox.

@DarkSideOfDay
Copy link
Author

As a workaround I have added pagination to my listbox (i.e. forward and back buttons), which eliminates the scrollbar and thus the issue never occurs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants