To define how changes are replicated between the data source and the UI, you can set the binding mode and update triggers for a binding object. You can set the binding mode and update triggers in UI Builder, UXML, or C#.
Binding modes configure how changes are replicated between the data source and the UI. The following binding modes are available:
Tip: Ensure that you set the appropriate binding mode based on your needs. For example, to prevent changes in the UI from being reflected in the source or if the UI is read-only, set the bindingMode
to BindingMode.ToTarget
.
You can update binding objects on every frame or when a change occurs in the data source. The following update triggers are available:
dirty
To define update triggers, use the following properties:
MarkDirty
: Sets the binding object as dirty
, so that it gets updated during the next cycle.updateTrigger
: Updates a binding object on every frame, regardless of the data source version.Note: Don’t keep binding types per-element state. You can use a binding instance across multiple elements and properties simultaneously. During updates and callbacks, the binding system passes in a context object that contains the target element, binding ID, and relevant data. You can use this context object to store the per-element state.