How to get the itemlistview details when a button is clicked ?

below is my Xaml :

        <controls:FlowListView x:Name="gallery"
                               FlowColumnCount="2"
                               SeparatorVisibility="Default"
                               HasUnevenRows="True"
                               FlowItemsSource="{Binding ItemsGallery}"
                               FlowUseAbsoluteLayoutInternally="True"
                               FlowItemTapped="OnFlowItemTapped"
                               FlowColumnExpand="Proportional"

                               BackgroundColor="White">
            <controls:FlowListView.FlowColumnTemplate>
                <DataTemplate>
                    <StackLayout>
                        <Frame BorderColor="#DCDCDC" HasShadow="True" Margin="2,2,2,2" CornerRadius="5">
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="100"/>
                                    <RowDefinition Height="35"/>
                                    <RowDefinition Height="20"/>
                                    <RowDefinition Height="20"/>
                                    <RowDefinition Height="35"/>
                                </Grid.RowDefinitions>
                                <ffimageloading:CachedImage Source="{Binding image}" Grid.Row="0" LoadingPlaceholder="ItemsGallery" HeightRequest="120" WidthRequest="120" />
                            <Label Grid.Row="1"
                               VerticalOptions="End"
                               FontAttributes="Bold"
                               FontSize="Medium"
                               HorizontalTextAlignment="Start"

                                   TextColor="Black"
                               Text="{Binding name}" />

                                <Label Grid.Row="2" HorizontalOptions="Start"
                               VerticalOptions="End"
                               FontAttributes="Bold"
                               FontSize="Medium"
                               Text="{Binding weight}" />

                                <Label HorizontalOptions="Start" Grid.Row="3" 
                               VerticalOptions="End"
                               FontAttributes="Bold"
                               FontSize="Medium"
                               Margin="2"
                               Text="{Binding price}" />
                                <Button Text="Add TO Cart"  Grid.Row="4" BackgroundColor="Coral" TextColor="WhiteSmoke" Clicked="Button_Clicked_1" />
                            </Grid>
                        </Frame>
                    </StackLayout>
                </DataTemplate>
            </controls:FlowListView.FlowColumnTemplate>
        </controls:FlowListView>

When a Add to cart button is clicked i want clicked row to add to local database.

Can any one please help me ,??

my cart.cs is below

    private async void Button_Clicked_1(object sender, EventArgs e)
    {

        if (((ListView)sender).SelectedItem == null)
            return;

        var myList = (ListView)sender;
        var myProuct= (myList.SelectedItem as ProductDetail);


    }
Tagged:

Best Answers

Answers

  • FirdousFarithFirdousFarith Member ✭✭

    Thank you so much Faizalsaidali and LeonLu

  • FirdousFarithFirdousFarith Member ✭✭
    edited June 17

    Thanks

  • FirdousFarithFirdousFarith Member ✭✭

    Hi @FaizalSaidali i tried to implement it but it says 'AddToCartCommand' property not found on 'ShoppingCarts.Model.Item', target property: 'Xamarin.Forms.Button.Command'

  • FaizalSaidaliFaizalSaidali USMember ✭✭✭

    @FirdousFarith , You can resolve it by adding reference of the page. See below code changes.

    <Button Text="Add TO Cart" Command="{Binding BindingContext.AddToCartCommand, Source={x:Reference gallery}CommandParameter="{Binding Id}" />

    The gallery is your FlowListView name. Its BindingContext will be the your page viewmodel(Default, otherwise you can set your content page name).

    More reference: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/xaml/xaml-basics/data-binding-basics#view-to-view-bindings

Sign In or Register to comment.