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

ListBox scrolling causes "The control already has a visual parent" #7621

Closed
SuperJMN opened this issue Feb 16, 2022 · 2 comments
Closed

ListBox scrolling causes "The control already has a visual parent" #7621

SuperJMN opened this issue Feb 16, 2022 · 2 comments
Labels

Comments

@SuperJMN
Copy link
Contributor

Describe the bug
Scrolling the items of a ListBox produces:

System.InvalidOperationException: 'The control already has a visual parent.'

To Reproduce

  1. Create a new Avalonia Application from template
  2. Open MainWindow.axaml
  3. Add this XAML to it:
    <ListBox>
         <ListBoxItem>asdfasdf</ListBoxItem>
         <ListBoxItem>asdfasdf</ListBoxItem>
         <ListBoxItem>asdfasdf</ListBoxItem>
         <ListBoxItem>asdfasdf</ListBoxItem>
         <ListBoxItem>asdfasdf</ListBoxItem>
         <ListBoxItem>asdfasdf</ListBoxItem>
         <ListBoxItem>asdfasdf</ListBoxItem>
         <ListBoxItem>asdfasdf</ListBoxItem>
         <ListBoxItem>asdfasdf</ListBoxItem>
         <ListBoxItem>asdfasdf</ListBoxItem>
         <ListBoxItem>asdfasdf</ListBoxItem>
         <ListBoxItem>asdfasdf</ListBoxItem>
         <ListBoxItem>asdfasdf</ListBoxItem>
     </ListBox>
  4. Run the application
  5. Resize the window so the ListBox shows a scrollbar. Make it show half of the items, approximately.
  6. Scroll down to show the hidden items, either with the mouse scroll-whell or with tapping the scrollbar control itself.
  7. You'll get the exception. You'll also notice that the last elements are shifted to the right side of the ListBox.

Expected behavior
No exception at all.

Desktop (please complete the following information):

  • OS: Windows 11
  • Version 22000.493

Additional context
Using Avalonia packages v0.10.12

@SuperJMN SuperJMN added the bug label Feb 16, 2022
@grokys
Copy link
Member

grokys commented Feb 16, 2022

Duplicate of #4265 (comment)

Solution for now is to disable virtualization if you're using inline ListBoxItems. I intended to fix this in #4779 but ItemsRepeater is so broken I gave up on it.

Maybe I'll have time to fix this sometime, who knows...

@grokys grokys closed this as completed Feb 16, 2022
@SuperJMN
Copy link
Contributor Author

Thanks, Steven! I'll use the workaround for now

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

No branches or pull requests

2 participants