我是Xamarin.form的初學者。當我點擊按鈕時,我想將產品添加到我的購物車中。我嘗試過,並不知道如何獲得這個項目併發送到購物車頁面。 這裏是我的Xmal位:如何將列表中的項目添加到其他頁面?
<ListView x:Name="productsListView" ItemSelected="OnProductSelected" HasUnevenRows="true" SeparatorVisibility="None" IsPullToRefreshEnabled="true" Refreshing="Handle_Refreshing">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell >
<StackLayout Orientation="Horizontal" Padding="2">
<Image Source="{Binding ImageUrl}"/>
<StackLayout HorizontalOptions="StartAndExpand" >
<Label Text="{Binding ProductName}" />
<Label Text="{Binding Price}" TextColor="Gray"/>
</StackLayout>
<Button Text="+" Clicked="Add_To_ShoppingCart" HorizontalOptions="EndAndExpand"/>
</StackLayout>
<ViewCell.ContextActions>
<MenuItem Text="AddToNotify"/>
<MenuItem Text="Delete" IsDestructive="true" Clicked="OnDeleteProduct" CommandParameter="{Binding .}"/>
</ViewCell.ContextActions>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
我不知道如何讓產品名稱和發送的購物車頁面,所以在購物車頁面可以從數據庫並顯示搜索。
按鈕代碼:
async void Add_To_ShoppingCart(object sender, System.EventArgs e)
{
//var product = (sender as Button).CommandParameter as Product;
//var shoppingcartPage = new ShoppingCartPage(product);
//shoppingcartPage.BindingContext = product.ProductID;
//await Navigation.PushAsync(shoppingcartPage);
var product = new Product()
{
ProductName= Guid.NewGuid().ToString()
};
var shoppingcarpage = new ShoppingCartPage(product);
shoppingcarpage.BindingContext = product;
await Navigation.PushAsync(shoppingcarpage);
//var product = HomepageListView.
//await conn.InsertAsync(product);
//_products.Add(product);
}
我試着像PushAsync單擊產品和它關係到商品詳細頁。我不想創建一個像這樣的新頁面。只需將商品添加到購物車即可。有什麼建議麼?
您可能想要查看購物車中的參考應用程序是如何工作的,eShopOnContainers,github.com/dotnet-architecture/eShopOnContainers'開放eShopOnContainers,MobileApps .sln只包含客戶端移動應用程序項目的解決方案(僅限Xamarin移動應用程序)。它也可以基於mocks獨立工作。' – SushiHangover