Reputation: 8225
I have this listview in Xamarin:
<ListView x:Name="LocationsListView"
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid Margin="10,10,10,10" Padding="5,5,5,5">
<StackLayout Grid.Column="0">
<Label x:Name="lblAirport" HorizontalOptions="Center" Text="{Binding AirportICAO}" />
<Button x:Name="btnConfirmFuel" IsVisible="{Binding AirportFuelSelected}" Clicked="BtnConfirmFuel_Clicked" CommandParameter="{Binding .}" />
</StackLayout>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
I want to get the item in the list which relates to the row where the button is clicked. Now I'm able to see the things I want to get through Clicked object sender parameter:
But when I'm trying to get the actual CommandParameter I don't get that as an option. What are my options, how can I detect from which item the button is clicked in the Xamarin Listview?
Upvotes: 0
Views: 350
Reputation: 89102
just cast the sender and get its CommandParameter
var item = (Model)((Button)sender).CommandParameter;
Upvotes: 2