Binding ItemSource of SfListView to an observableCollection

Hi,


In the sample application attached, I want to bind TapView Products to TapModel Products.

I am not able to bind the list properly.

Could you please help.


Thanks

Sonal


Attachment: GestureRecognizer_72ea8bb7.zip

1 Reply

LN Lakshmi Natarajan Syncfusion Team February 22, 2022 12:26 PM UTC

Hi Sonal, 
 
We suggest you create the bindable property as mentioned below, 
 
TapView 
public static readonly BindableProperty ProductListProperty = BindableProperty.Create( 
    nameof(ProductList), typeof(ObservableCollection<Product>), typeof(TapView), null, 
    BindingMode.Default, null, (bindable, oldValue, newValue) => 
    { 
        ((TapView)bindable).ItemsSource = (ObservableCollection<Product>)newValue; 
    }); 
 
public ObservableCollection<Product> ProductList 
{ 
    get { return (ObservableCollection<Product>)GetValue(ProductListProperty); } 
    set { SetValue(ProductListProperty, value); } 
} 
 
You can also refer to the following documentation to create bindable property in Xamarin.Forms, 
 
Also, you need to create the property as the type of the model collection (i.e., ObservableCollection<Products>), or else binding error will be thrown.  
 
We have modified the sample to achieve your requirement and attached in the following link, 
 
Please let us know if you need further assistance. 
 
Lakshmi Natarajan 
 


Loader.
Up arrow icon