Adding data bindings
Data binding is the heart and soul of MVVM. This is the way that the views and ViewModel communicate with each other. In .NET MAUI, we need two things to make data binding happen:
- We need an object to implement
INotifyPropertyChanged
. - We need to set the
BindingContext
class of the page to that object. We already do this on bothItemView
andMainView
.
A useful feature of data binding is that it allows us to use two-way communication. For example, when data binding text to an Entry
control, the property on the data-bound object is updated directly. Consider the following XAML:
<Entry Text="{Binding Title}" />
To make this work, we need a property named Title
on the string object. We have to look at the documentation, define an object, and let IntelliSense provide us with a hint to find out what type our property should be.
Controls that perform an action, such as Button
, usually expose a property called Command
. This property...