Motivated by the comment of @Jason on my first answer to this post i got curious to know if he was right when he said:
there is no reason you can't set ItemsSource directly in code
and after a bit of research i found out that as he pointed out, the code in my answer was doing fundamentally the same as the code of the OP. But... how did then my answer help OP to solve the problem?
Well, the only way i can get the exception
Object reference not set to an instance of an object
using the code in the original post is if the c# code posted is called before InitializeComponent() is called, that is, if the code behind looks like:
public MainPage()
{
List<UserClass> users = new List<UserClass>();
users = webService.getScannedLog();
BindingContext = this;
lst.ItemsSource = users;
InitializeComponent();
}
in which case lst is being called before it is even created by InitializeComponent().
In that case, my answer solved the issue by removing lst reference and setting ItemsSource directly in XAML.
If that is the case, at all, then i would like to say that to solve the issue it is enough to move the setting of ItemsSource after the call to InitializeComponent(), in which case the code would look something like:
public MainPage()
{
InitializeComponent();
List<UserClass> users = new List<UserClass>();
users = webService.getScannedLog();
BindingContext = this;
lst.ItemsSource = users;
}
@user979331, please let me know if this is the case.