Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon How does the syntax of Fluent Databinding differ from that of Swiss Databinding


How does the syntax of Fluent Databinding differ from that of Swiss Databinding


Fluent and Swiss data binding are two different approaches used in MvvmCross for creating bindings between the view and the view model. Here's how their syntax differs:

Fluent Data Binding

Fluent data binding uses a C#-based syntax to create bindings. It is particularly useful in platforms like iOS and OSX where XML layout files are not easily human-editable. The syntax involves chaining methods to specify the binding details. For example, to bind a label's text property to a view model's `TweetText` property with a converter, you would use:

csharp
this.CreatingBinding(label)
    .For(l => l.Text)
    .To(vm => vm.TweetText)
    .WithConversion("RemainingLength", 140);

This syntax allows for clear and expressive binding definitions directly in code.

Swiss Data Binding

Swiss data binding uses a cleaner, less verbose syntax compared to its predecessor, JSON binding. It is designed to be easily included in XML layout files. The syntax involves specifying the target property and the source path directly. For example, to bind a label's text property to a view model's `TweetText` property with a converter, you would use:

xml
Text TweetText, Converter=RemainingLength, ConverterParameter=140

This syntax is concise and straightforward, making it easy to read and write bindings directly in XML files or similar configurations.

Key Differences

- Syntax Style: Fluent uses a C#-based, method-chaining syntax, while Swiss uses a more declarative syntax similar to XML attributes.
- Usage Context: Fluent is more suitable for platforms where code-based bindings are preferred (e.g., iOS, OSX), while Swiss is better for configurations that can be easily read or written in XML files.
- Verbosity: Fluent can be more verbose due to its method-chaining nature, while Swiss is concise and directly specifies the binding details.
- Converter and Parameter Handling: Both support converters and parameters, but Fluent does so through method calls (`WithConversion`), while Swiss uses a comma-separated list of attributes (`Converter=RemainingLength, ConverterParameter=140`).

Citations:
[1] https://docs.devexpress.com/WindowsForms/113956/cross-platform-app-development/winforms-mvvm/concepts/data-bindings-and-notifications
[2] https://docs.nativescript.org/guide/data-binding
[3] https://www.mvvmcross.com/documentation/fundamentals/value-converters
[4] https://www.mvvmcross.com/documentation/fundamentals/data-binding
[5] https://en.wikipedia.org/wiki/Data_binding
[6] https://stackoverflow.com/questions/75622438/how-to-bind-values-when-using-fluentselect
[7] https://github.com/microsoft/fluentui-blazor/issues/3184
[8] https://developer.apple.com/tutorials/app-dev-training/passing-data-with-bindings
[9] https://www.reddit.com/r/dotnetMAUI/comments/10jeuue/data_binding_not_working_correctly_for_fluent_ui/