Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

ListView gets refreshed only after I scroll after updating an item

$
0
0

Hello,

I am creating a shopping cart app and I am stuck in between with Listview refresh. I have a view cell in my list view and it has a Image button. When I click on the image button based on the model parameter(bool) I am replacing the image. After I update the model property, my listview is not getting refreshed automatically. Refresh happens only after I scroll the ListView.

Is there anything I am missing in below code?

Code: View cell in list view-
<ImageButton

                                            Grid.Row="0"

                                            Grid.Column="1"

                                        Margin="5,10,10,5"

                                        Aspect="AspectFit"

                                        BackgroundColor="Transparent"

                                        Command="{Binding Path=BindingContext.CartCommand, Source={x:Reference product}}"

                                        CommandParameter="{Binding .}"

                                        HorizontalOptions="End"

                                        Source="{Binding WishListImageIcon}"

                                        VerticalOptions="Center" />

View model:

public ICommand CartCommand { get; private set; }

private void UpdateCartImage(Electronics electronic)

        {

            if (electronic.WishList)

            {

                electronic.WishList = false;



            }

            else

            {

                electronic.WishList = true;



            }



            int pos = ElectronicList.IndexOf(electronic);

            ElectronicList.RemoveAt(pos);

            ElectronicList.Add(electronic);

        }

Model:

public bool WishList

        {

            get { return _wishList; }

            set { SetValue(ref _wishList, value); }

        }



        public string WishListImageIcon

        {

            get { return WishList ? "icon_wish_click.png" : "icon_wish_unclick.png"; }



        }

I am new to Xamarin. Kindly help me to resolve the issue.

Thanks,
Prasanna


Viewing all articles
Browse latest Browse all 89864

Trending Articles