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, 2D effects, 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 that you can control with that property. See Tutorial: Create gauges.

../../_images/binding-rotation.png

Bind the position or size of one node to the position or size of another node. See Tutorial: Making applications with dynamic layout.

../../_images/binding-size.png

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.

Components of a binding

A binding has these components:

  • Target item, which can be a node, render pass, 2D effect, state, state object, or style.

  • Target property and, optionally, property field.

  • Source returned by a binding expression.

The source can be a property or property field of a node, render pass, 2D effect, 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 (TextConcept.Text) property of a Text Block node to the Value property of a Slider node. The Text Block node is the target item, Text is the target property, and the Value (RangeConcept.Value) property of the Slider node is the source. See Tutorial: Creating a slider.

Binding modes

Binding mode sets the direction of data flow in the binding:

  • One way binding changes the value of a target property when the value of a source property changes.

    In a one-way binding, you can bind the target property to a binding expression. See Bindings expressions reference.

    Note

    When you use a state manager, action, or a style to set a local property value, that removes any one-way binding that targets the property. See Value source bindings.

  • To Source binding sets:

    In a to-source binding, you can bind the target property to a binding expression. See Bindings expressions reference.

  • Two way binding changes the value of a target property when the value of a source property changes, and the other way around.

    In a two-way binding, you can bind a target property only to a source property. See Creating a two-way binding.

Binding types

These types of bindings are available in Kanzi:

  • Value Sources

    A value source binding sets the local value of an entire property and provides the value for that property during application runtime.

    See Value source bindings.

  • Modifiers

    A modifier binding modifies a property value, much like an animation or a state manager.

    See Modifier bindings.

  • To Source

    A to-source binding pushes a property value to a node or another project item, or to a resource used by that item.

    See To-source bindings.

../../_images/properties-binding-types.png

Value source bindings

A value source binding sets the local value of an entire property and provides the value for that 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.

A value source binding replaces any previously set local property value.

Kanzi removes a value source binding when:

  • Setting the property value by other means replaces the previously set local value.

  • The local property value is removed.

For example:

  • A one-way value source binding that sets the Text property of a Tex Box node stops working when the user edits the text. To update the text with a binding, use a to-source or two-way binding instead. See Using a binding to update the text in a Text Box node.

  • A one-way binding that sets the Toggle State property of a Toggle Button node stops working when the user toggles the button. To update the property value with a binding, use a to-source or two-way binding. See Using a binding to update the toggle state.

Modifier bindings

A modifier binding modifies a property value, much like an animation or a state manager.

A modifier binding either:

  • Sets the value of a property field.

    For example, bind the Layout Transformation property 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.

  • Accesses 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 modifier bindings after value Sources bindings. A modifier binding does not replace a local property value.

To-source bindings

A to-source binding pushes a property value to a node or another project item, or to a resource used by that item.

For example, use a to-source binding to:

Material type bindings

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. You can refer to this variable in other bindings in the same material type.

    See Temporary variable bindings.

See also

Using bindings

Customizing instances of prefabs

Bindings expressions reference

Tutorial: Create gauges

Tutorial: Making applications with dynamic layout

Tutorial: Creating a slider

Tutorial: Rotate a 3D model

Data sources

Material types and materials

Using render passes

Effects for 2D nodes