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

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

Open
igorstefus opened this issue May 17, 2021 · 3 comments
Open

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

igorstefus opened this issue May 17, 2021 · 3 comments
Labels
bug Something isn't working

Comments

@igorstefus
Copy link

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

@igorstefus igorstefus added the bug Something isn't working label May 17, 2021
@grokys
Copy link
Member

grokys commented May 17, 2021

This seems to be the way ItemsRepeater was designed to work. From the MS docs:

https://docs.microsoft.com/en-us/windows/uwp/design/controls-and-patterns/items-repeater#bringing-an-element-into-view

Bringing a virtualized element into view involves the following:

  1. Realize a UIElement for an item
  2. Run the layout to ensure the element has a valid position
  3. Initiate a request to bring the realized element into view

WPF has the UpdateLayout method which makes it a bit less ugly, maybe we should just add UpdateLayout to ItemsRepeater?

@grokys
Copy link
Member

grokys commented May 17, 2021

UWP has the UpdateLayout method on UIElement: https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.uielement.updatelayout?view=winrt-19041 but the reason we dont have it is (from the UWP docs):

Layout updates can be forced by app code rather than relying on the built-in layout system behavior by using the UpdateLayout method. However, that is not generally recommended. It is usually unnecessary and can cause poor performance if overused.

Which is also true for Avalonia, so we make it a bit more difficult by having to get the layout manager etc. but given that doing a manual layout is necessary for ItemsRepeater we could expose UpdateLayout on ItemsRepeater.

@igorstefus
Copy link
Author

igorstefus commented May 17, 2021

Yeah that make sense. At least user doesn't need to hunt for LayoutManager. If noting more to make it more streamlined :)

@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