State & Binding

State & Binding

Manage application data and connect it to your UI dynamically. Nimbus makes state management effortless.


Variables

Variables store data that can be used across your application. They are defined inside the <Logic> block using the <Var> tag.

App.xml
<Logic>
    <!-- String -->
    <Var Name="username" Value="John Doe" Type="string"/>
    
    <!-- Integer -->
    <Var Name="count" Value="0" Type="int"/>
    
    <!-- Boolean -->
    <Var Name="isLoggedIn" Value="false" Type="bool"/>
    
    <!-- Double (Decimal) -->
    <Var Name="price" Value="19.99" Type="double"/>
</Logic>

Supported Types

TypeDescription
stringText (Default).
intWhole numbers.
doubleDecimal numbers.
boolTrue or False.
listComma-separated values (array).

Data Binding

Binding allows you to display variable values in the UI automatically. Use the curly brace syntax {variableName}.

sync_alt

Two-Way Sync

When you update a variable in Logic, the UI updates instantly.

text_fields

String Interpolation

Combine text and variables: Hello {name}!

<!-- Direct Binding -->
<TextBlock Text="{count}"/>

<!-- Interpolation -->
<TextBlock Text="Welcome back, {username}!"/>

<!-- Property Binding -->
<Button Content="Click" IsEnabled="{isActive}"/>
bolt
Hot Tip: Bindings work in attributes too! You can bind colors, sizes, and visibility. E.g., Width="{widthVar}".

Manipulating State

Use logic commands to change variable values.

Set Variable

Update a variable's value.

<Set Var="username" Value="Jane Doe"/>
<Set Var="isLoggedIn" Value="true"/>

Math Operations

Perform calculations on numeric variables.

<!-- Increment / Decrement -->
<Increment Var="count" By="1"/>
<Decrement Var="lives" By="1"/>

<!-- Multiply / Divide -->
<Multiply Var="price" Value="2"/>
<Divide Var="total" Value="4"/>

<!-- Complex Calculation -->
<Calculate Expression="{price} * {qty} + {tax}" ToState="total"/>

Control State

You can read and write properties of UI controls directly, without using a separate variable.

Get Control Property

Read a value from a control (like TextBox input) into a variable.

<!-- Read text from input box into 'name' variable -->
<Get Control="txtName" Property="Text" ToState="name"/>

<!-- Read slider value -->
<Get Control="sldVolume" Property="Value" ToState="vol"/>

Set Control Property

Directly modify a control's property.

<!-- Change button text -->
<Set Target="btnSubmit" Property="Content" Value="Processing..."/>

<!-- Change background color -->
<Set Target="pnlMain" Property="Background" Value="#FF0000"/>

Direct Binding

You can even bind one control's property to another directly.

<!-- Bind Label text to TextBox input -->
<TextBlock Text="{txtInput.Text}"/>