I have a ListView, some of the items should be selectable, some not.
All items are able to be selected no matter the state I put them and all their children into.
I’ve tried setting PickingMode.Ignore and also SetEnabled(false) on the items I don’t want to be selectable.
They still trigger the onSelectionChange callback and have the “unity-collection-view__item–selected” class added to them.
Is there a way during makeItem or bindItem (or otherway) to prevent the item being selectable?
Currently I’m forced into doing checks in the onSelectionChange callback to check if the item should be selectable, which seems a bit late in the process.
One oddity is that in runtime the UI Toolkit Debugger isn’t able to select the items I’ve attempted to disable but the pointer in game can.
I would like to browse in the list without selecting any element but when I drag the list elements they got white background.
I’ve tried severeal API methods but nothing helped.
I am waiting a way to do this in the future.
You might be able to stop the background color issue by setting one (or all) of the pseudo-classes -
:hover, :active , :focus, :selected in your uss file to transparent.
As far as I can tell this specific use case is not supported out of the box. For one thing, the reason setting individual items to PickingMode.Ignore doesn’t work is because the ListView registers its events on its entire contentContainer and uses local position to know which item is being pressed.
Your workaround seems reasonable. Another thing you can do is take over selection entirely by setting the ListView.selectionType to SelectionType.None and registering your own events on items during bindItem and calling SetSelection yourself.