We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Serious failure in ItemsSource property when you have a constructor in ModelView with parameters on Android only.

Thread ID:

Created:

Updated:

Platform:

Replies:

150338 Jan 2,2020 06:33 PM UTC Jan 9,2020 12:30 PM UTC Xamarin.Forms 3
loading
Tags: SfListView
Guilherme
Asked On January 2, 2020 11:29 PM UTC

When binding the ItemsSource in the listview or dataform it just doesn't load on Android when my ViewModel has parameters in the constructor.
It took me many days to figure out the error since the failure does not occur on the UWP platform.
I noticed that this affects all syncfusion controls when I use ItemsSource.

In Constructor ContentPage:
...
InitializeComponent();
BindingContext = new ViewModel.PrincipalViewModel(this);
...

In ModelView:

public class PrincipalViewModel
{
     readonly ContentPage _page;
     public ObservableCollection<<>> Items { get; set; }     // Not Working in Android Platform Only

     public class ModelView(ContentPage page)  // Not Working in Android Platform Only
     {
          _page = page;
     }
}

In XAML:

syncfusion:SfListView x:Name="listView" ItemSize="60"
                                                   ItemsSource="{Binding Items}"/

Greetings from Brazil.


Gnana Priya Namasivayam [Syncfusion]
Replied On January 3, 2020 07:08 AM UTC

Hi Guilherme, 
 
Thanks for using Syncfusion products. 
 
We are not clear with the reported query “When ViewModel has a parameter it affects all syncfusion controls when I use ItemsSource.” and provided code snippets are not clear to understand your requirement exactly. Can you please share your use case with the viewmodel parameter and your requirement in detail to validate your query at our end. 
 
Regards,  
Gnana Priya N

Guilherme
Replied On January 8, 2020 12:48 PM UTC

Simply the ItemsSource properties of any control does not work with MVVM when it has parameterized constructor.

Take the test and you'll find that on the UWP platform it works normally, but on Android it doesn't work.

Gnana Priya Namasivayam [Syncfusion]
Replied On January 9, 2020 12:30 PM UTC

Hi Guilherme, 
 
We have checked by passing parameter to our viewmodel as mentioned in our sample using latest ListView 17.4.0.41 and Xamarin Forms 4.4 version. We have checked the reported issue in all platforms like UWP, iOS & Android but the reported issue did not occur in our sample in Android. We have attached the tested sample for your reference, please find them from following link. 
 
 
 
Model.cs 
public class Contacts : INotifyPropertyChanged 
{ 
   public Contacts(string name, string number) 
   { 
      contactName = name; 
      contactNumber = number; 
      displayString = name[0].ToString(); 
   } 
} 
 
ViewModel.cs 
 
public class MainPageViewModel  
{ 
    public MainPageViewModel( ContentPage page) 
    { 
        ContactsInfo = new ObservableCollection<Contacts>(); 
        foreach (var cusName in CustomerNames) 
        { 
            var contact = new Contacts(cusName, r.Next(720, 799).ToString() + " - " + r.Next(3010, 3999).ToString()); 
            contact.ContactImage = ImageSource.FromResource("ListViewPrism.Images.Image" + r.Next(0, 28) + ".png", assembly); 
            contact.ContactColor = Color.FromRgb(r.Next(40, 255), r.Next(40, 255), r.Next(40, 255)); 
            ContactsInfo.Add(contact); 
        } 
     } 
   } 
} 
MainPage.xaml.cs 
 
public partial class MainPage : ContentPage 
{ 
   MainPageViewModel viewModel; 
   public MainPage() 
   { 
      InitializeComponent(); 
      viewModel = new MainPageViewModel(this); 
      this.BindingContext = viewModel; 
   } 
} 
 
 
 
Can you please check above sample whether you are getting reported issue in our sample also. If not, revert us back with the issue replicated sample so that we can analyze and provide you better solution at our end. 
 
Regards, 
Gnana Priya N 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon