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.
<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
| Type | Description |
|---|---|
string | Text (Default). |
int | Whole numbers. |
double | Decimal numbers. |
bool | True or False. |
list | Comma-separated values (array). |
Data Binding
Binding allows you to display variable values in the UI automatically. Use the curly brace syntax {variableName}.
Two-Way Sync
When you update a variable in Logic, the UI updates instantly.
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}"/>
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}"/>