Search code examples
xamarincollectionviewstepper

The stepper control in the collectionView ,how to get the rowindex in xamarin?


The stepper control in the collectionView,When the ValueChanged event be triggered ,Can I get the rowindex?

My question is as same as "https://stackoverflow.com/questions/53737450/how-to-get-selected-indexpath-from-a-stepper-located-inside-a-collection-view-ce"

,but It is the ios swift soulution. In the Xamarin programming ,I have no idea how to do it ?


Solution

  • if your CollectionView's ItemsSource is a List<Widget> then each cell will be bound to a single Widget and you can reference the related widget in the event handler. You don't need the index of the row, you can directly reference the bound object

    void ValueChanged(object sender, EventArgs args)
    {
      var stepper = (Stepper)sender;
      var widget = (Widget)stepper.BindingContext;
    
      ...
    }