Can I make a custom ScrollView in UI Toolkit

Hi,

I want to make a custom ScrollView which can dynamic show many item by few ui items.
I’ve read “UI builder and custom elements”( UI builder and custom elements ). I wonder should I write a class inherit from VisualElement or ViewList. And is there any api could help me realize that function.

Thank you

The ListView demo shows: it will recycle item. Is this your foucs on “few ui items”?

1 Like

Yes, the goal of the ListView is to create as few elements as possible to fit the visible area of a scroll view.

In general you do need to inherit from ListView, you just configure it with the required callbacks.

1 Like

Yes, that’s the function what I need.
I used to add VisualElement into list directly but not bind data on it. Now I’m learning it. Quite confusing…

Hello, I finally figured out how to use ListView and bind data on it. And I want it works as grid in UGUI.
I bind a two-dimensional array on ListView and it works fine. I don’t want its default hang over and selected effect style, how could I change it or is my direction correct?

Thanks.

You can change the style of the ListView by overriding the default style with your own USS file.
To get started have a look at the elements you want to change in the UI Toolkit debugger, look at their USS classes and override them in your USS file.

User defined styles always take precedence over default one so you can totally change the look with this approach.

Made it! Great thanks to you!