Reputation: 67
I am using xamarin form for developing a mobile application, in the "user_page" I am showing in a ListView the last order of the user and I have added the possibility to select a specific order for getting more information about it.
This is my xaml code:
<ListView x:Name="Wash_list">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.ContextActions>
<MenuItem Clicked="OnMore"
CommandParameter="{Binding .}"
Text="More Info" />
<MenuItem Clicked="OnQR"
CommandParameter="{Binding .}"
Text="QR_Code" />
<!--IsDestructive="True"-->
</ViewCell.ContextActions>
<StackLayout Padding="15,0">
<Label Text="{Binding washType}"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
And this is my C# code (I am stuck on it..):
async public void OnMore(object sender, EventArgs e)
{
int i = 0;
HttpClient _Client = new HttpClient();
var content = await _Client.GetStringAsync(urlTrade);
var get = JsonConvert.DeserializeObject<List<WashBuyData>>(content);
var mi = ((MenuItem)sender);
for (i = 0; i <= get.Count ; i++)
if (true)
await DisplayAlert("About " + mi.CommandParameter, "Buy on: " + get[i].timestamp, "OK");
}
So...what I want to do is showing specific info from the selected item, how I can do this? I have tried to pick the text value or the id from the selected item for set my "i" param but without success...
Upvotes: 1
Views: 1091
Reputation: 373
So.. Add ItemTapped="OnItemTapped"
in your ListView
<ListView x:Name="Wash_list"
ItemTapped="OnItemTapped">
After, add on CodeBehind.
void OnItemTapped(Object sender, ItemTappedEventArgs e)
{
var dataItem = (YourModel)(e.Item);
}
Upvotes: 4