Enabling interactions on custom controls
In real-world applications, controls often serve dual roles – they both display data and allow users to interact with it. In this section, we’ll further enhance our FavoriteControl
to not only support user interactions through IsFavoriteChangedCommand
but also to facilitate two-way data binding. These features will make the control more interactive and further align it with MVVM concepts. We want to allow users to tap the Image
on the FavoriteControl
. When FavoriteControl
’s IsEnabled
property is set to true
, the IsFavorite
property will be updated and IsFavoriteChangedCommand
will be executed.
Let’s take a look at the first part of this functionality – updating the IsFavorite
property when a user taps on the image and making sure the value bound to this property gets updated as well.
User actions and reflecting state
To start with, let’s add the ability for users to toggle their favorite state...