Bindings¶
Use bindings to set the value of a property or property field with the value from another property, property field, or a data source.
Bindings allow nodes, render passes, states, state objects, and styles to automatically update the values of their properties in response to the changing property values, or the occurrence of some external event.
For example, you can:
Bind the rotation property field of a node to a property to create a gauge needle which you can control with that property. See Tutorial: Create gauges.
Bind the position or size of one node to the position or size of another node. See Tutorial: Making applications with dynamic layout.
With bindings you can modularize your Kanzi project:
Use bindings in prefabs to provide access only to those properties that you want to set to different values in different instances of the prefab. See Customizing instances of a node prefab.
Use bindings with data sources to separate the presentation of the user interface from the application data and to remove the dependencies between a Kanzi Studio project and the application code which defines the Kanzi application. This way you can build your Kanzi application according to the Model–View–Controller pattern. See Data sources.
For example, you can bind the presentation of a speed needle in the user interface to the data value which represents speed in your application. See Using a data source.
The simplest of bindings bind a property of a node to one of its own properties. You can also bind properties and property fields of one node to those of several different nodes. See Using bindings.
A binding has these components:
Target item, which can be a node, render pass, state, state object, or style.
Target property and, optionally, property field.
Source, which can be a property or property field of a node, render pass, state, state object, style, or data object.
For example, to use a text block to show the current value of a slider, you can bind the Text property of a Text Block 2D node to the Value property of a Slider 2D node. The Text Block 2D node is the target item, Text is the target property, and the Value property of the Slider 2D node is the source.
Binding mode sets the direction of data flow in the binding:
To change the value of the target property when the value of the source property changes, use a One way binding. In a One way binding you can bind the target property to a binding expression. See Bindings expressions reference.
To change the value of the source property when the value of the target property changes, use a To Source binding. To Source binding is the reverse of One way binding.
To change the value of the target property when the value of the source property changes, and the other way around, use a two-way binding.
In a Two way binding you can bind the target property to a source property or property field. See Creating a two-way binding.
In Kanzi Studio these types of bindings are available:
Value Sources bindings set the value of an entire property and provide the value for the property during application runtime.
For example, bind the Layout Height property of a 2D node to the Layout Width property of that node, or bind the Text property of a Text Block 2D node to the position of another node. See Creating simple bindings and Binding to the properties of other nodes.
Modifiers bindings either:
Set the value of a property field.
For example, bind the Rotation property field of a node to the Scroll Position property of a Scroll View node to rotate the node using swiping gestures. See Tutorial: Rotate a 3D model.
Access a value source in a binding expression.
For example, bind the Render Transformation property Translation Y property field of a node to the Render Transformation property Translation X property field of the same node to make that node move on the y axis the same distance as it moves on the x axis. See Modifying the value of the property that you bind and getCurrentValue.
Kanzi executes Modifiers bindings after Value Sources bindings.
To Source bindings push a property value to another project item.
Material types have their own special types of bindings for:
Uniforms
Uniform bindings enable you to modify the values of shader uniforms used by a material type without making changes to the shader code.
See Uniform bindings.
Temporary Variables
In a material type a temporary variable binding enables you to store the result of a binding into a temporary variable to which you can refer in other bindings in the same material type.
See also¶
Tutorial: Making applications with dynamic layout
Bindings expressions reference