0
我想创建一个列表视图,用户可以选择列表项来查看商店,也可以点击图像将它们带到产品详细信息中。 如何在ViewCell中添加命令?如何使用MVVM在xamarin listview中添加多个命令按钮?
<ListView ItemsSource="{Binding myData}" x:Name="myListView" SelectedItem="{Binding SelectedStore}" >
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid>
<Label Text="{Binding Title}" />
<Image Source="product.png" >
<Image.GestureRecognizers>
<TapGestureRecognizer Command="{Binding ItemTapCommand}" CommandParameter="Id" />
</Image.GestureRecognizers>
</Image>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
public ICommand ItemTapCommand => new Command(ShowSelectedProductAsync());
private async Task ShowSelectedProductAsync()
{
//take them to view the item detail
}
我不清楚UserControl上。此代码位于xaml页面中,我没有将其用作嵌入xaml页面的usercontrol。你是这个意思吗?如果不是什么将MyUserControl? – wil
@wil:在具有正确的'BindingContext'的xaml图形中的更高位置。我假定它是一个'UserControl',但它可以很容易地成为一个'Page'或其他更高级别的东西。哎呀,你甚至可以使用ListView,因为它已经有一个名字(myListView)。 –
这就是我的想法。非常感谢。今晚我会试试这个。 – wil