Skip to content

reference databinding

Reisen Usagi edited this page Apr 10, 2018 · 9 revisions

DataBinding

JankyUI Supports Two-Way DataBinding.

  • Data is automatically read from your ViewModel when it needs to be displayed
  • Data is automatically written to your ViewModel when it has changed
  • Methods are automatically called when a Control is interacted with

Data Context

The initial data context is the ViewModel passed when creating the JankyUI.

At any Control or Container XML Element you may change the data context to another one relative from its parent like so:

<Button data-context='InnerDataContext' text='@BoundProperty' on-click='@BoundMethod' />

Note the data-context attribute doesn't receive the @ character

You may also delve multiple properties at once like so:

<Button data-context='InnerDataContext.WeNeedTo.GoDeeper' text='@BoundProperty' on-click='@BoundMethod' />

When used in Container Nodes, all children will also share the new Data Context.

Member Access

Binding targets must be public Properties or Fields, static or instance, and their value must also be public.

A private class behind a object member will not work

Naming

Binding targets names must adhere to the following format:

  • One character from A to Z or a underscore (No digits, Case insensitive)
  • Any number of characters from A to Z, 0 to 9, or a underscore (Case insensitive)

Valid Examples:

Identifier, _identifier, i_am_valid, _123, _abc123

Invalid Examples:

123abc, with spaces, special$character

Notation

Bindings on the XML side are identified by the @ chacater before the Member name inside the XML Node attribute:

<Button text='@BoundProperty' on-click='@BoundMethod' />

If your text has to start with @ and it is not a Binding, escape it with another @ character:

<Label text='@@I Am Not Bound' />