Pass object in click/tapped event handler in Xamarin Forms

梦想的初衷 提交于 2019-12-05 03:39:17

try:

        lstView.ItemTapped += async (o, e) => {
            var myList= (ListView)o;
            var myJob = (myList.SelectedItem as Job);
            await DisplayAlert("Tapped",  myJob.Id, "OK");
            myList.SelectedItem = null; // de-select the row
        };

The following page explains exactly what you are looking for: Selecting an Item in a ListView

listView.ItemSelected += async (sender, e) => 
{
    await DisplayAlert("Tapped!", (e.SelectedItem as Job).Id + " was tapped.", "OK");
};

If you want to navigate to a detail page passing arguments then use the following:

listView.ItemSelected += async (sender, e) => 
{       
      var jobPage = new JobPage(e.SelectedItem as Job); // new page shows correct data          
      await Navigation.PushAsync(jobPage);
};
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!