I’m trying to construct shopping system with UI Toolkit.
While I used ListView to display item list, I noticed MultiColumnListView is better for more detailed infomation.
So I have just replaced ListView to MultiColumnListView, then result is great like this!
But it causes a problem on Focus().
Without Focus(), user is required one more control to start selection in item list.
It’s just little irritating, so I use Focus() method for smooth navigation.
ListView.Focus() works well for this.
This is my simplified method to open shopping window.
Even though _itemListView was originally ListView, be replaced to MultiColumnListView.
public void OpenShop(ShopData shopData)
{
_isShopMode = true;
_shopWindow.style.display = DisplayStyle.Flex;
_targetShopData = shopData;
_itemListView.itemsSource = _targetShopData.Items;
_itemListView.RefreshItems();
_itemListView.SetSelection(0);
_itemListView.Focus();
Debug.Log(_root.focusController.focusedElement);
}
This doesn’t work correctly on focusing. (Again, ListView.Focus() does work correctly.)
Console out this.
Then I came up with a solution, it’s to use Focus() on UnityContentContainer in hierarchy of MultiColumnListView. (Its ID is “unity-content-container”)
_itemListView.RefreshItems();
_itemListView.SetSelection(0);
// Instead of MultiColumnListView.Focus()
_unityContentContainer.Focus();
Debug.Log(_root.focusController.focusedElement);
This has resolved my problem. But console out this.
This is same to MultiColumnListView.Focus().
This behavior is what is intended?
In my opinion, it doesn’t seems to be working.