Bindable Property is not working in content view for pass an uri

Andrea Ciullo 21 Reputation points
2022-06-22T16:47:00.147+00:00

This is the scenario:

I have a ContentView with string bindable property for send an uri string and show an image.

the problem is, if i send an bindable string the property change isn't fires, but manualy it's fire correcty.

    public string ProductImageURL  
        {  
            get { return (string)GetValue(ProductImageUrlProperty); }  
            set { SetValue(ProductImageUrlProperty, value); }  
        }  
  
        public static readonly BindableProperty ProductImageUrlProperty = BindableProperty.Create(  
           propertyName: nameof(ProductImageURL),  
           returnType: typeof(string),  
           declaringType: typeof(ProductCardHorizontal),  
           defaultBindingMode: BindingMode.TwoWay,  
           propertyChanging: ImageUrlChanged  
         );  
  
        private static void ImageUrlChanged(BindableObject bindable, object oldValue, object newValue)  
        {  
            if (bindable != null && newValue != null)  
            {  
                var control = (ProductCardHorizontal)bindable;  
                control.productImage.Source = (string)newValue;  
            }  
        }  

This call dont work

   <contentViews:ProductCardHorizontal  
     
                                   ProductImageURL="{Binding Item.ImageURL}"  
                          />  

And if i put some url it's work

   <contentViews:ProductCardHorizontal  
     
                                   ProductImageURL="https://i.postimg.cc/fypffMwS/Avene.png"  
                          />  
Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,261 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 64,576 Reputation points Microsoft Vendor
    2022-06-23T08:28:04.1+00:00

    Hello,​

    Do you use <contentViews:ProductCardHorizontal> in ListView or CollectionView? And you have list in the ViewModel like following code.

       public List<Item> lists { get; set; }  
    

    If so, please binding ImageURL directly, remove Item like following xaml.

       <contentViews:ProductCardHorizontal  
                                       ProductImageURL="{Binding ImageURL}"  
                              />  
    

    If not, please share your layout code. And add an breakpoint in control.productImage.Source = (string)newValue; line, check if you get value from binding property.

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful