Search Unity

ListView binding-path

Discussion in 'UI Toolkit' started by wang37921, Apr 9, 2020.

  1. wang37921

    wang37921

    Joined:
    Aug 1, 2014
    Posts:
    102
    i using ListView binding-path bind a List with 2 items.
    But it invoke 3 times listView.bindItem callback.
     
  2. havchr

    havchr

    Joined:
    Jun 18, 2009
    Posts:
    75
    I think it is because it is sending the first item as the size of the list. It is a bit weird. You can test it by having a ScriptableObject with just a simple array field and then displaying it without any custom view - the UIElements example project should have that setup as well. What will happen is that it will default to :
    header view displaying nr of Items in list :
    list view item 0
    list view item 1
    etc..
    I had to offset my indices to account for this fact.

    So the example you should check is the ListViewBinding.cs in the UIElementsExample project.
    This just calls root.Bind(serializedObject) - so no listView.binding - but you can see - it creates a header to display the size of the list. I hope this was helpful.
     
    Last edited: Apr 12, 2020
  3. wang37921

    wang37921

    Joined:
    Aug 1, 2014
    Posts:
    102
    thx, if not set the bindItem&makeItem callback, it will show the header and listItem. the information is helpful.
     
  4. wang37921

    wang37921

    Joined:
    Aug 1, 2014
    Posts:
    102
    ListView using Bind will show the header to display the size of the list; using ItemSource, not showing.
     
  5. uMathieu

    uMathieu

    Unity Technologies

    Joined:
    Jun 6, 2017
    Posts:
    398
    This behavior was meant to replicate the default inspector's PropertyField on Arrays. From 2020.1 onwards, you can control this using the ListView.showBoundCollectionSize property.
     
    wang37921 likes this.