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, usually in a realization of the MVVM (Model-View-ViewModel) application architecture. When using Zebble, you can use the MVVM pattern thanks to its support for Data Binding, but you don't have to. (If you're not familiar with MVVM, there are plenty of resources on the web to get you started).
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.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.
As you may remember 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:
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.
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".
Let's say you have a DateTime property:
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 binding, or a full MVVM architecture.