how to pass data from list view to new page with viewmodel

Hi, im implementing a shopping cart app, in that i have products list. From product list to product details page i am passing the list data . now i want to add a button to add to cart that particular product.

i am confused how to do that with a view model

here is my code.

on selected list item im passing product details

                Navigation.PushAsync(new ProductDetailsPage(item));

This is my product details page

            <StackLayout Spacing="10">

                <ScrollView  >
                    <StackLayout Spacing="10" x:Name="layout">

                        <Label TextColor="Black" FontSize = "24" Text="{Binding name}" FontAttributes="Bold"/>
                        <Image Source="{Binding image}" />

                        <StackLayout Spacing="10" Orientation="Horizontal">
                            <Label TextColor="Gray" FontSize = "18" Text="Price:" />
                            <Label TextColor="Black" FontSize = "18" Text="{Binding price}" FontAttributes="Bold" />
                        </StackLayout>

                        <StackLayout Spacing="10" Orientation="Horizontal">
                            <Label TextColor="Gray" FontSize = "18" Text="SKU:" />
                            <Label TextColor="Black" FontSize = "18" Text="{Binding sku}" FontAttributes="Bold" />
                        </StackLayout>


                        <Label TextColor="Gray" FontSize = "18" Text="Description:" />
                        <Label TextColor="Black" FontSize = "18" Text="{Binding description}" />


                    </StackLayout>
                </ScrollView>

                <Button Text="Add to cart"  TextColor="Black" HeightRequest = "50" BackgroundColor = "Gray" VerticalOptions="End"/>

            </StackLayout>

in code behind im binding the product

            public ProductDetailsPage(Products product)
            {
                InitializeComponent();

                Debug.WriteLine("product val {0}", product.name);
                Debug.WriteLine("product images  {0}", product.images);

                BindingContext = product;



            }

id i want to add button with command with view model, how can i set the product details value ?

                <Button Text="Add to cart"  TextColor="Black" HeightRequest = "50" BackgroundColor = "Gray" VerticalOptions="End"/>

Best Answers

Answers

Sign In or Register to comment.