So, im again try to learn how works UI Elements. In this case im create EditorWindow for scriptableObject. Geting list of items from source, and attached them to ListView
(example source code)
var tree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/ModelsDb/Styles/WindowBase.uxml");
var listView = new ListView();
Func<VisualElement> makeItem = () =>
{
return tree.CloneTree();
};
Action<VisualElement, int> bindItem = (e, i) =>
{
var foldout = e.Q<Foldout>("_foldout");
foldout.value = modelsBase.models[i].isExpanded;
e.style.height = foldout.value ? 140 : 30;
foldout.RegisterValueChangedCallback(evt =>
{
e.style.height = evt.newValue ? 140 : 30;
modelsBase.models[i].isExpanded = evt.newValue;
listView.Refresh();
});
foldout.text = "Item";
};
listView.bindItem = bindItem;
listView.makeItem = makeItem;
listView.itemsSource = modelsBase.models;
listView.itemHeight = 140;
InitListView(listView);
rootVisualElement.Add(listView);
I have two problems now. When im clicked on Foldout, it change height of current item and state of bool in SO. But with the first item, the last one changes too. And another problem related to rendering of elements that were outside of the rendering at the time of the bool state change. These problems are visible on the GIF.