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

list view button image change in load

$
0
0

Hi friends , in my app i have a cart option, items are adding to cart is from a list view , also cart is other list view. While i add item to cart the i can change the image. Initially the button image is + and it will change to - i fond this code from https://forums.xamarin.com/discussion/comment/156279/#Comment_156279 . my problem is while i came back to the page all button changes to + .
I need to bind the button image inside list view according to a condition i,e if the value exist in the cart the image should me - else image should be - .
This problem was discussed early in forms and i got some Knowles from that discussion
my button code

btn_Cart = new ImageButton{
                BackgroundColor = Color.Transparent,
                VerticalOptions = LayoutOptions.CenterAndExpand,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
            };
             var addedOrNotImageBinding = new Binding("IsAddedToCart", 0, new ImagePathConvertor());
            btn_Cart.SetBinding(ImageButton.SourceProperty, addedOrNotImageBinding);

ImagePathConvertor

public class ImagePathConvertor : IValueConverter{
        public ImagePathConvertor() { }
        #region IValueConverter implementation
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if ((bool)value) {
                return "minus";
            }
            else{
                return "add";
            }
        }
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture){
            throw new NotImplementedException();
        }
        #endregion
    }

you can see the first image which i add some items to cart added item is change to - other remain to + but if i go back and came again to this page the image all + like the second image


Viewing all articles
Browse latest Browse all 75885

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>