I was trying to add reorderable list view to my graph node’s extension container.
The List View that does not cause problems when added to the Graph View’s rootVisual but when I add in graph node it not working at all.
Here is the all cases
Working Case
private static void TestCase1()
{
_instance.rootVisualElement.Add(TestCaseListView());
}
Problem Case
private static void TestCase2()
{
var node = new Node();
var contentSpace = new VisualElement();
contentSpace.name = "Content Space";
contentSpace.style.width = 200;
contentSpace.style.height = 100;
contentSpace.style.backgroundColor = Color.white;
contentSpace.style.flexGrow = 1;
contentSpace.style.flexShrink = 1;
node.extensionContainer.Add(contentSpace);
var foldout = new Foldout();
foldout.style.flexGrow = 1;
foldout.style.backgroundColor = Color.grey;
contentSpace.Add(foldout);
foldout.Add(TestCaseListView());
node.RefreshExpandedState();
GPView.Instance.AddElement(node);
}
And also here is list view creation same as api doc
private static ListView TestCaseListView()
{
const int itemCount = 10;
var items = new List<string>(itemCount);
for (int i = 1; i <= itemCount; i++)
items.Add(i.ToString());
Func<VisualElement> makeItem = () => new Label();
Action<VisualElement, int> bindItem = (e, i) => (e as Label).text = items[i];
const int itemHeight = 16;
var listView = new ListView(items, itemHeight, makeItem, bindItem);
listView.selectionType = SelectionType.Multiple;
listView.itemsChosen += objects => Debug.Log(objects);
listView.selectionChanged += objects => Debug.Log(objects);
listView.style.height = 200;
listView.style.width = 100;
listView.reorderable = true;
listView.reorderMode = ListViewReorderMode.Animated;
listView.style.flexGrow = 1.0f;
listView.style.flexShrink = 1.0f;
return listView;
}
