Register Property to BindableProperty
First, you will need to register the name of property that you want to add. To achieve this, you need to create a class in Core project that inherits BindableProperties, and register the name and type of the property to BindableProperty.
Add BindingAdapter Class in Android and iOS Project
Since the view's API is different in Android, iOS and WinPhone – for example EditText in Android and UITextField in iOS – then you need to add BindingAdapter class in every platform project and define what you would like you to do with the view in association to the custom bindable property. When the value in the bound model change, Crosslight's binding framework automatically invoke the binding adapter associated to the view. This allows the view to react seamlessly in response to the value change.
In this example, the binding adapter class will set the text size of Android's EditText and iOS's UITextField based on the bound value in ViewModel.
Register BindingAdapter in AppInitializer
Next, you register the binding adapter by calling the AddBindingAdapter<TControl, TAdapter> method in AppInitializer.cs of your Android and iOS project. The API usage is straightforward, you simply pair the control type with its corresponding binding adapter in the provided generic parameters, such as shown in the example code below.
Use Custom BindableProperties in Binding Provider
Finally, you can now consume the custom TextSize bindable property in the BindingProvider, and bind it to a property in ViewModel in the same way as built-in bindable properties does.
Change TextSize Property in ViewModel
With the TextSizeProperty bound to TextSize property, now you can change the control's text size in both iOS and Android by simply changing the TextSize property in ViewModel.
The result will look like this: