Get cell Item when click on a view of the cell?

rubenyesrubenyes ESMember

Hello I have the following code:

    <ListView x:Name="listview"
            ItemTapped="Handle_ItemTapped"
            HasUnevenRows="True"
            CachingStrategy="RecycleElement">

        <!--Custom View Cells-->
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <StackLayout Orientation="Horizontal" Padding="5">
                        <Image Source="{Binding Foto}" HeightRequest="50"/>
                        <StackLayout HorizontalOptions="StartAndExpand">
                            <Label Text="{Binding Nombre}" FontSize="Large" />
                            <Picker x:Name="picker" Title="Selecciona la mezcla" ItemsSource="{Binding PosiblesSubItems}" 
                                    ItemDisplayBinding="{Binding Nombre}" SelectedIndexChanged="Handle_PickerChanged" />
                        </StackLayout>
                        <Label Text="{Binding PrecioTotal, StringFormat='{0:F2}€'}" VerticalOptions="Center" FontSize="Large"/>
                        <Button Text="+" HorizontalOptions="Start" VerticalOptions="Start" />
                    </StackLayout>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>

    </ListView>

And I want to get the Item related to the cell of the listview where is the picker changed by the user. So I want to get the Item inside the method "Handle_PickerChanged", how i can do it?

Thnak you in advance :)

Best Answer

  • RyanDixonRyanDixon US ✭✭✭
    Accepted Answer

    The binding context should be inherited from the parent, and the parent in turn is applied as part of the templating process.
    For example:

    var picker = sender as Picker;
    var item = picker.BindingContext as ItemType;
    
    // Perform actions with item here.
    

Answers

  • RyanDixonRyanDixon USMember ✭✭✭
    Accepted Answer

    The binding context should be inherited from the parent, and the parent in turn is applied as part of the templating process.
    For example:

    var picker = sender as Picker;
    var item = picker.BindingContext as ItemType;
    
    // Perform actions with item here.
    
Sign In or Register to comment.