Can you use the new UI Toolkit Data Binding on List Views?

Hi @SkywardAssembly !

Sorry, I didn’t catch this post quickly. So the announcement has been made here .

Regarding the ListView, I would say that it’s partially supported in the runtime bindings system. I say partially because you can use the DataBinding type to create bindings between your data and the bindable properties of the ListView, however the ListView requires a little bit more logic to function properly.

So the best way to use the new system with the ListView control is to do the following:

  • Create a VisualTreeAsset to contain the UI of the list item.
  • Set the asset created in 1. as the itemTemplate of the ListView. This is a new property that we added to make it easier to setup the ListView and to use the new binding system.
  • Set the bindingSourceSelectionMode to AutoAssign. What this will do is that it will set the itemsSource as the dataSource of each item and it will prefix the dataSourcePath with the correct index.

You can use bindings to set the itemsSource itself and the other various properties of the ListView. You should note however that the itemsSource property is not available in the UI Builder, so the binding must be manually added in the UXML file.

What makes the support partial is:

  • It won’t call the ListView.RefreshItems() or ListView.Rebuild() for you whenever the list size changes. Depending on what you are doing, this can be achieved by creating a CustomBinding that tracks the size of the itemsSource and call refresh whenever it changes.
  • If the ListView is refreshed or rebuilt after the binding operations has been completed, your ListView might be temporarily displaying outdated information.

This will be part of the “Current limitations & what’s next” part of the announcement, but I haven’t had time yet to write it.

Hope this helps!

3 Likes