Search Unity

Question How do I preview/edit a ListView item when its contents are generated by code?

Discussion in 'UI Toolkit' started by darthdeus, Oct 16, 2020.

  1. darthdeus

    darthdeus

    Joined:
    Oct 13, 2013
    Posts:
    80
    Using a `ListView` which is instantiated in code in order to set its `itemsSource`, `makeItem` and `bindItem` parameter, can I somehow use the UI Builder to create the actual item, or even better preview what the ListView would look like with a bunch of items filled in?
     
    florianhanke likes this.
  2. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    Better late than never. The short answer is no. However, you can create a custom control (that inherits from VisualElement), that includes a ListView inside. You custom control can set the necessary bindings while also exposing custom UXML attributes for use in the UI Builder to control these bindings. One such attribute can be a path to the UXML for each item. If you set it right, you should be able to select a row in your ListView that is cloned from say "row.uxml", and in the Hierarchy choose "Open as Sub-Document In-Place". This will open just that one UXML inside the host UXML that contains the ListView. Then, every time you save the child UXML in this mode, you should see the changes in the parent (and for all other rows). It won't be live but should increase iteration speed somewhat.