Say, I have a custom element with an attirbute “text”. Is there a way for me to bind value to it directly instead of relying on the “binding-path”?
So, in WPF (which is the most similar UI framework to Unity’s), to bind a value in XML you do this:
<TextBlock Text="{Binding Source={StaticResource myDataSource}, Path=Name}"/>
Is there something equivalent?
You mean like this?
<engine:DataBinding property="text" data-source-path="Attack" data-source-type="Futsal.Team+PlayerID, Futsal.Runtime" binding-mode="ToTarget" update-trigger="OnSourceChanged" />
full code
<engine:UXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:engine="UnityEngine.UIElements" xmlns:editor="UnityEditor.UIElements" xmlns:appui="Unity.AppUI.UI" noNamespaceSchemaLocation="../../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
<Futsal.LabelCellListPlayer column="ATK" style="min-height: 40px; -unity-text-align: middle-center;">
<Bindings>
<engine:DataBinding property="text" data-source-path="Attack" data-source-type="Futsal.Team+PlayerID, Futsal.Runtime" binding-mode="ToTarget" update-trigger="OnSourceChanged" />
</Bindings>
</Futsal.LabelCellListPlayer>
</engine:UXML>
I haven’t come across this syntax before (and autocomplete doesn’t seem to work). Which version are you using?
That’s the runtime binding introduced in 2023.2. There’s a comparison of runtime and SerializedObject binding here. If you need editor binding that deals with data from a SerializedObject, you’ll be sticking with UXML binding paths or binding in code. Otherwise, once you upgrade to Unity 6, you can access runtime binding and use the syntax like shown above.
Ah, I was actually making editor UI. I also use 2022.3, so the syntax is beyond my reach unfortunately.