Binding SerializedObject (List<Class>) to ListView

Hello. I haven’t found any working example of how to do this:

There is a certain classes:

public enum Langs
    {
        EN,
        ARA
    }

[Serializable]
public class LocalTextDirectionType
 {
        public Langs Lang
    }

public class SomeClass {
    public List<LocalTextDirectionType> someProperty;

}

There is a custom inspector, in which there is the ListView

 [CustomEditor(typeof(SomeClass)), CanEditMultipleObjects]
    public class Some: Editor
    {
        public override VisualElement CreateInspectorGUI()
        {
VisualElement rootInspector = new VisualElement();
_list = new ListView()
            {
                virtualizationMethod = CollectionVirtualizationMethod.DynamicHeight,
                showFoldoutHeader = true,
                headerTitle = "Localized",
                showAddRemoveFooter = true,
                reorderMode = ListViewReorderMode.Animated,
                makeItem = () => CreateAlignmentRow(),
                bindItem = (element, i) =>
                {
                    
                }, 
                bindingPath = "someProperty",
            };
rootInspector.Bind(serializedObject)
rootInspector .Add(_list)
}

}

And I get an error:

ArgumentException: Can't find array size property!
UnityEditor.UIElements.Bindings.SerializedObjectList.RefreshProperties () (at <d66e1a49bb1b4f56b6bbb21deaafcac2>:0)
UnityEditor.UIElements.Bindings.SerializedObjectList..ctor (UnityEditor.SerializedProperty parentProperty) (at <d66e1a49bb1b4f56b6bbb21deaafcac2>:0)
UnityEditor.UIElements.Bindings.ListViewSerializedObjectBinding.SetBinding (UnityEngine.UIElements.ListView targetList, UnityEditor.UIElements.Bindings.SerializedObjectBindingContext context, UnityEditor.SerializedProperty prop) (at <d66e1a49bb1b4f56b6bbb21deaafcac2>:0)
UnityEditor.UIElements.Bindings.ListViewSerializedObjectBinding.CreateBind (UnityEngine.UIElements.ListView listView,

I try:
bindingPath = "someProperty.Array", but this also doesn’t work correctly

Please help me Bind serializedObject with ListView

Have you tried finding the property for the collection and .Bind-ing that directly to the list view?

Yes, If I create my own list

List<LocalTextDirectionType> myList = new();

 SerializedProperty localTextDirectionProperty = serializedObject.FindProperty("someProperty.Array");
            for (int i = 0; i < localTextDirectionProperty.arraySize; i++)
            {
                SerializedProperty element = localTextDirectionProperty.GetArrayElementAtIndex(i);
                myList .Add((LocalTextDirectionType)element.boxedValue);
            }

It’s work, but this result not saved (because not bind with serializedObject)

You should be using PropertyField’s and binding them to each of the collection’s serialized properties.

Can you give me a sample? If you can. Thanks

Hello! Does this help at all? Unity - Manual: Bind to a list with ListView

You can use SetBinding to bind the Item source of the listView