When creating a binding in Xamarin.Forms, the default is that you create an OneWay binding (except for input elements that have TwoWay bindings), this means that it updates the view from the ViewModel whenever the value in the ViewModel changes. But often you don't need a OneWay binding, you only need a OneTime binding, but you use OneWay just because it is the default. A OneTime binding only reads the value once, if the property changes after that, the UI is not updated. That means that the UI doesn't need to listen to changes in the ViewModel, and that can affect performance in a good way.
If you are familiar with UWP development and compiled bindings with x:Bind you may know that there is OneTime default and the reason for that is that it gives you a more performant app. So why not use it with Xamarin.Formas as well.
To use OneTime binding one tip from the Jason Smith, one of the founders of Xamarin.Forms, according to this tweet:
OneTime bindings when you don't need to actually track changes can have large performance benefits.
— Jason Smith (@jassmith87) April 3, 2020
In this post, I will show some scenarios where you can use OneTime binding. But I recommend you to use it whenever possible.
When using CollectionView
You maybe will change the data source for a CollectionView (read below for a static data example), so you still need a TwoWay binding there, and often you will set the value of the property after that you have fetched data from a data source. But inside your DataTemplate, you can often use OneTime bindings, and if you have some elements that need to listen for changes, you can use OneTime bindings just for those elements.
When using Commands
When using commands in ViewModels, you often write to them like below, and you never change the value of the property.
In this case, there is no need to use the default OneWay binding because you know that the value of the property will never change.
When having static data
Sometimes you need to bind an element to a collection of static data, for example when you are using a CarouselView or a CollectionView where you specify the data in a ViewModel. The reason that you want to do that is that you can't add items to those elements directly (you can specify ItemSource in XAML if you want).
The property in the ViewModel:
A CarouselView that binds to the property: