Is it possible to bind dataSource and Localization in UI Toolkit?

Hello,

I’m trying to connect data initialized in my script to variable in the Localization binding. Is it even possible?
It works well for simple data type (like string, int, float, etc) but when I want to bind that directly to a Locale Variable, I don’t find any solution.

Here is my data declaration:

public class ProvinceDataBindings
{
    public string Title;
    public int Population;
    public float SoilFertility;
}

Then, my data initialization:

public readonly ProvinceDataBindings ProvinceData = new();

public void OnNavigateFrom(string provinceName)
{
    ProvinceData.Title = provinceName;

    // Root is equivalent to UIDocument.rootVisualElement.Q("MyView");
    Root.dataSource = ProvinceData; 
}

And, in UI Builder, this is my binding setup:

I dont think this will work at the moment, although it does sound like a good idea.
LocalizedStrings dont currently have any context, they dont know they are attached as a binding to the panel.
Are you able to share an example project showing what you are trying to do? I can use it to create a task for us to add the feature.

Ok, as I suspected, it’s not yet possible.

This is the project setup you asked for. It works with a CharacterData used on the CharacterView template and placed on VisualElement.dataSource.

UITK-Localization-DataSource-1680780.zip (86.5 KB)

2 Likes

Thanks. I have created a task for us to take a look at adding this support in the future.

2 Likes