I’m following this example for ListView https://docs.unity3d.com/Packages/com.unity.ui@1.0/api/UnityEngine.UIElements.ListView.html#UnityEngine_UIElements_ListView and I need to use a list entry more complicated than a simple Label.
I’ve created a class (called ListEntry)., that extends VisualElement, to hold four labels ListEntry will contain a method to do the binding of another object (ListItem) to the ListEntry.
How would I create the itemMake and ItemBind parameters to do that, or am I fundamentally misunderstanding this?
Hi @niel-archer !
There’s a simple example on how to set up a ListView in the sample window. (Window/UI Toolkit/Samples)
Would something like this work for your use case ?
Action<VisualElement, int> bindItem = (e, i) => (e as ListEntry).item = items*;```*
I saw that example, and as stated in OP, I have a more complicated entry with more than one field. I have found a way to do it using similar method to that example, but I would really like to put the code into the class for the new ListEntry so that it is all together and I don’t have to crawl through hundreds or thousands of lines of code to find it if/when it needs to be updated.
I think I understand. You could add a BindItem method in your ListEntry class that holds the binging logic. Then call this method in the bindItem callback. The result would look something like this.
Action<VisualElement, int> bindItem = (e, i) => (e as ListEntry).BindItem(items[i]);
Does it answer your question?
Many thanks. That looks like what I am after. I will give it a try as soon as I can find time.
1 Like
Thanks for your help, that was exactly what I needed.