Data bindings allow properties of two objects to be linked so that a change in one causes a change in the other. This is a very valuable tool, and while data bindings can be defined entirely in code, Zebble markup provides shortcuts and convenience.
Bindings are used most often to connect the visuals of an app with an underlying data model to enable the MVVM (Model-View-ViewModel) application architecture.
Data bindings connect properties of two objects, called the source and the target. The first step is to define a source property in your code-behind class to which your view properties will be bound.
To set a value for this property you can either use the Set() method or the Value property. For example:
MyProperty.Set("New value");
// Or:
MyProperty.Value = "New value";
As soon as a new value is set, all target objects which are bound to this will have their specified property updated as explained below.
In Zebble markup, you can use the @... value prefix syntax to specify a dynamic C# expression as opposed to a literal value.
// Or to benefit from intellisense and compile time checking:
MyProperty.AddBinding(MyTextView, nameof(MyTextView.Text));
There are times when you may want to bind the target property to a function of a bindable property (source) as opposed to its direct value. In those cases you can specify an optional lambda expression to provide the conversion logic.
Example 1:
Let's say you have a Bindable<int> property whose value may change at runtime.
In the above example, the visible property (which is boolean) is being data-bound to a function of the bindable value which is defined as a lambda expression "x => x != 0" and is seperted by a comma from the name of the bindable property "MyProperty".
Example 2:
Let's say you have a DateTime property:
Background of data binding syntax in .NET
If you have any experience with MVVM implementations such as WPF, Xamarin Forms or UWP, you may know that to define a bindable property in such frameworks you have to write a lot more code, compared to Zebble. In those frameworks to just create a bindable property you have to do all of the following:
None of this is required in Zebble as the Bindable<TValue> class will take care of everything. All you need to do is to define a readonly instance of Bindable<...> in your class. This means that in Zebble it's much quicker, cleaner and easier to implement data bindings to implement a full MVVM architecture.