[英]ItemSelected on ListView and more information about the object (Xamarin.Forms, C #)
I have a problem.我有个问题。 In my xamarin.forms application I have a listview that gets as a source:
在我的 xamarin.forms 应用程序中,我有一个作为源的列表视图:
var tr = JsonConvert.DeserializeObject<Items>(content);
myList.ItemsSource = tr.cars;
Classes for this data:此数据的类:
public class Items
{
public List<Car> cars { get; set; }
}
public class Car
{
public int id { get; set; }
public string company { get; set; }
public Owner owners { get; set; }
}
public class Owner
{
public int o_id { get; set; }
public string o_surname { get; set; }
}
I would like to view more information by clicking on an object in the listview.我想通过单击列表视图中的 object 来查看更多信息。 I use this in xaml ItemSelected="OnSelection" and in code:
我在 xaml ItemSelected="OnSelection" 和代码中使用它:
void OnSelection(object sender, ItemTappedEventArgs e)
{
Car myitem = sender as Car;
DisplayAlert("ItemSelected", $"{myitem.company.ToString()}", "Ok");
}
This give me error: Object reference not set to an instance of an object.'这给了我错误:Object 引用未设置为 object 的实例。
I found some information about item selected, but none solved my problem.我找到了一些关于所选项目的信息,但没有一个能解决我的问题。
ItemTappedEventArgs
contains a reference to your item ItemTappedEventArgs
包含对您的项目的引用
void OnSelection(object sender, ItemTappedEventArgs e)
{
Car myitem = e.Item as Car;
DisplayAlert("ItemSelected", $"{myitem.company.ToString()}", "Ok");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.