Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

How to tag a Button?

$
0
0

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 of Buttons can vary at run time.
  • Each Button is associated with a feature in the app and is bound to the same ICommand 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 a FeatureViewModel argument) is executed.

A workaround would be for the Page to maintain a mapping of Button to FeatureViewModels and have each button's Clicked handler execute the view model's ICommand, which seems cheesy. :(


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>