Data binding
Let’s explore how MVVM and data binding works. We can use an item detail page implementation in our app to analyze how data binding works. The following list includes the view, ViewModel, and model that we are going to explore:
- View:
ItemDetailPage
, see Listing 3.4 in the previous chapter - ViewModel:
ItemDetailViewModel
, see Listing 4.1 - Model:
Item
(access through the IDataStore interface), see Listing 3.3 in the previous chapter
ItemDetailPage
is a view used to display the content of an instance of Item
. The data is retrieved from the ViewModel. The UI elements presenting the content of Item
are connected to the ViewModel instance through data binding.
Figure 4.4: Data binding
As we can see in Figure 4.4, data binding is used to synchronize the properties of target and source objects. There are three objects involved in data binding and they are the binding target
, binding source
, and binding object
.