如何解决Xamarin - 如何在点击时从列表视图中的 ImageCell 获取数据绑定字符串值?
我对 Xamarin 还很陌生,我在弄清楚如何获取图像单元格的绑定值时遇到了问题。
我有一个使用 ImageCell 的列表视图,如下所示,我将 itemSelected 命令设置为名为“selectedBox_Tapped”的列表视图
<Grid>
<ListView x:Name="itemListView" ItemSelected="selectedBox_Tapped">
<ListView.ItemTemplate>
<DataTemplate>
<ImageCell Text="{Binding Name}"
Detail="{Binding Compound}"
ImageSource="defaultimage.png">
</ImageCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
在后面的 C# 代码中,我正在尝试这个
private async void selectedBox_Tapped(object sender,ItemTappedEventArgs args)
{
string name = ????
await Navigation.PushAsync(new DetailsPage(name));
}
我希望能够从 ImageCell 中获取 {Binding Name} 的字符串值,然后将其作为构造函数传递给我的 DetailsPage,如上所示。
where String name = ???? 我不知道我需要做什么来完成这项工作。
感谢您的帮助:)
解决方法
使用ItemTappedEventArgs
private async void selectedBox_Tapped(object sender,ItemTappedEventArgs args)
{
// args.Item will be the context of the tapped cell
// you will need to cast it to the correct class
var item = (MyClass)args.Item;
// once item is cast,you can just refer to its properties
await Navigation.PushAsync(new DetailsPage(item.Name));
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。