Hi @CDF,
For you example, since it’s relatively simple and you are already writing most of the code, I would use the makeItem/bindItem directly, something like that:
listView.itemsSource = testData.items;
listView.makeItem = new ImageItem();
listView.bindItem = (element, index) => (element as ImageItem).vakye = testData.items[i];
For the longest time I couldn’t get this to work, until I added the
[CreateProperty]attribute on the “value” property. Without that attribute the console spams: “[UI Toolkit] Could not set value for target of type ‘ImageItem’ at path ‘value’: the path is either invalid or contains a null value. (TestEditor)”
For this, I would refer you to the documentation about defining a data source.
I also need to set:
listView.bindingSourceSelectionMode = BindingSourceSelectionMode.AutoAssign;otherwise the same warning logs.
What this does is assign the listView.itemsSource as the dataSource and set the proper dataSourcePath for each list item automatically for you. For simple cases where you want to map the list item directly to a custom element, I would prefer to use makeItem/bindItem.
Event if my data class implements
INotifyBindablePropertyChangedandIDataSourceViewHashProviderthe list is constantly refreshing the value. How can I avoid this?
In this case, you would need both the collection type and the item type to implement change tracking interfaces. We currently have only partial support for this. You can find more information in this post.
Hope this helps!