In MvvmCross, One-Time binding and One-Way binding are two distinct data binding modes that serve different purposes.
One-Time Binding
One-Time binding transfers data from the ViewModel to the View only once, when the binding source is initially set. After this initial transfer, the binding does not monitor changes in the ViewModel and does not update the View unless the binding source itself is reset. This mode is useful for fields that are configurable but do not change frequently after they are set. For example, in MvvmCross, One-Time binding is used for setting static text from language files, as it is common for users to select a language once and not change it frequently thereafter[1].
One-Way Binding
One-Way binding, on the other hand, continuously updates the View whenever the corresponding property in the ViewModel changes. This means that any changes to the ViewModel's property will automatically be reflected in the View. However, changes made directly to the View do not affect the ViewModel. One-Way binding is useful when displaying data that comes from a dynamic source, such as sensor data or network feeds, where the View should reflect the latest state of the ViewModel but does not need to send updates back to it[1].
Key Differences
- Update Frequency: One-Time binding updates the View only once at setup, while One-Way binding continuously updates the View whenever the ViewModel changes.
- Change Monitoring: One-Time binding does not monitor changes in the ViewModel after the initial setup, whereas One-Way binding actively listens for changes in the ViewModel.
- Use Cases: One-Time is ideal for static or infrequently changing data, while One-Way is better suited for dynamic data that needs to be displayed in real-time without user interaction affecting the ViewModel.
In summary, while both modes transfer data from the ViewModel to the View, One-Time binding does so only once and does not monitor for changes, whereas One-Way binding continuously updates the View based on ViewModel changes.
Citations:[1] https://www.mvvmcross.com/documentation/fundamentals/data-binding
[2] https://blog.ostebaronen.dk/2018/01/mvvmcross-binding-target.html
[3] https://stackoverflow.com/questions/41768962/mvvmcross-default-binding-mode-used-in-a-project
[4] https://www.mvvmcross.com/documentation/fundamentals/viewmodel-lifecycle
[5] https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/data-binding/binding-mode?view=net-maui-9.0
[6] https://yanxiaodi.gitbook.io/xamarin-mvvmcross-handbook/using-mvvmcross-to-create-your-first-xamarin-app/creating-the-android-project/understanding-the-data-binding-syntax
[7] https://www.mvvmcross.com/documentation/advanced/custom-data-binding
[8] https://github.com/MvvmCross/MvvmCross/issues/29
[9] https://stackoverflow.com/questions/27803448/data-binding-one-vs-two-way
[10] https://stackoverflow.com/questions/48910503/binding-mode-onetime-in-mvxrecyclerview
[11] https://www.reddit.com/r/javascript/comments/v993r4/askjs_why_is_oneway_binding_better_than_twoway/