I have a collection: List which I wanted to use as the source (as ListView just passes this to the Bind handler anyhow, and relies on it’s size).
list = root.Q<ListView>();
list.makeItem = () => new Label();
list.bindItem = (e, i) => (w as Label).text = Checklist.Items[i].Name;
list.itemsSource = Checklist.Items(); //List<CheckListItem>()
list.selectionType = SelectionType.Single;
list.onItemChosen += obj => OnItemChosen(obj as CheckListItem);
The above does literally nothing when I call Refresh().
itemSource seems to only work from a collection of strings, so to make it work, I had to do this:
private List<string> GetProxy()
{
var list = new List<string>();
for (var i = 0; i < Checklist.ChecklistItems.Count; i++)
list.Add(Checklist.ChecklistItems[i].Name);
return list;
}
And everytime I need to refresh the list I have to do:
list.itemsSource = GetProxy();
list.Refresh();
And then it magically works and displays my items (while I now have to synchonize an extra list of strings just for this to actually function on every refresh)…
Since we have to setup our own makeitem, binditem and source handlers, why does this not work when i pass in a source of List<CustomClass>?
Seems like a bug.
Passing in string lists, also means now that onItemChosen now returns a string instead of my custom class type, so now I have to work with indexes instead.