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