这是我的工作类:
public class Job
{
public string Id{ get; set;}
public string Name{ get; set;}
}
这是我的 ListView:
public class JobListePage:ContentPage
{
// Members
private ListView lstView;
// Constructor
public JobListePage ()
{
// Set members
lstView = new ListView ();
// Create job objects
Job[] jobs = {new Job(){Id="1", Name="Benny"}, new Job(){Id="2", Name="Lukas"}};
// Fill listview with job objects
lstView.ItemsSource = jobs;
// HOW CAN I PASS THE TAPPED OBJECT HERE???
lstView.ItemTapped += async (o, e) => {
await DisplayAlert("Tapped", "HERE I WANT TO SHOW THE ID", "OK");
((ListView)o).SelectedItem = null; // de-select the row
};
....
现在如何将点击的“工作对象”传递给事件?
您可以看到我向用户显示了一条消息。在那里它应该代表被点击对象的 ID。
最佳答案
尝试:
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
};
关于c# - 在 Xamarin Forms 的点击/点击事件处理程序中传递对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28985571/