In many UI frameworks, the base UI element class (in XForms, a View
) contains a .Tag
property that allows a reference to an object be associated with the View
. Is there an equivalent in Xamarin Forms?
My use case is the following:
- My Page constructs a collection of Buttons that are children of a
StackLayout
. The number ofButton
s can vary at run time. - Each
Button
is associated with a feature in the app and is bound to the sameICommand
in the page's view model. - I would like to associate (i.e. tag) each Button with a
FeatureViewModel
so that when the user clicks any button, the command (which takes aFeatureViewModel
argument) is executed.
A workaround would be for the Page
to maintain a mapping of Button
to FeatureViewModel
s and have each button's Clicked
handler execute the view model's ICommand
, which seems cheesy.