How to populate a ListView from FireBase

Hi I am using Xamarin Forms with firebase, I am trying to populate a listview in the view "NavigationListCardPage"
The listview  Binding is NavigationList (ItemsSource="{Binding NavigationList}"), which is  an ObservableCollection<NavigationModel>

in the file: NavigationListCardPage.xaml.cs
public NavigationListCardPage(int Rol)
        {
            this.InitializeComponent();
            Task.Run(async () =>
            {
                this.BindingContext = await myownDataFireBaseCards("1", 1); 
            });
            //this.BindingContext = 
                //NavigationDataService.Instance.NavigationViewModel;
        }

private async Task<NavigationViewModel> myownDataFireBaseCards(string IDperson, int Rol)
        {
            FirebaseClient firebaseClient = new FirebaseClient(MyGlobal.RealDataBaseURL);
            var allCasas = await firebaseClient.Child("Prueba").OnceAsync<Models.NavigationModel>();
            NavigationViewModel navigationViewModel;
            var Devolver = new ObservableCollection<Models.NavigationModel>();
            foreach (var Casa in allCasas)
            {
                Devolver.Add(new Models.NavigationModel
                {
                    ItemDescription = Casa.Object.ItemDescription,
                    ItemImage = "Recipe19.png", // Casa.Object.ItemImage,
                    ItemName = Casa.Object.ItemName,
                    ItemRating = Casa.Object.ItemRating,
                }); 
            }
            
            var Retorname = new NavigationViewModel { NavigationList = Devolver };
            return Retorname;
}
I check and "Retorname" is indeed an ObservableCollection<NavigationModel> with two objects, but I do not know why ListView is empty
What can I do to this works?





4 Replies 1 reply marked as answer

RK Ranjith Kumar Durairaj Syncfusion Team June 2, 2021 02:13 PM UTC

Hi Mike

Currently we are analyzing the attached sample from our side. We will update further details on or before June 4th, 2021. We will appreciate your patience until then. 
Regards,
Ranjith kumar
 



LN Lakshmi Natarajan Syncfusion Team June 4, 2021 12:06 PM UTC

Hi Mike, 
 
Thank you for using Syncfusion products. 
 
We have checked the reported query “How to populate a ListView from FireBase” from our side. We have analyzed the given sample and we would like to inform you that you can overcome the issue by setting the BindingContext in the UI thread. 
 
Please refer to the following code snippets, 
public partial class NavigationListCardPage 
{ 
    public NavigationListCardPage(int Rol) 
    { 
        this.InitializeComponent(); 
        Device.BeginInvokeOnMainThread(async () => 
        { 
            this.BindingContext = await myownDataFireBaseCards("1", 1);  
        });      
    } 
... 
 
Please let us know if this helps. 
 
Regards, 
Lakshmi Natarajan 


Marked as answer

MI Mike June 5, 2021 11:54 PM UTC

HI, It works perfectly, many thanks.
I would like to know why if possible.


LN Lakshmi Natarajan Syncfusion Team June 7, 2021 06:24 AM UTC

Hi Mike, 
 
Thank you for the update.  
 
We are glad that your requirement has been met at your side. We would like to inform you that you can only update the UI from the UI thread. For example, binding changes that update the UI should be reflected when updating from the UI thread. 
  
Please refer the same mentioned in the following links,  
 
Please let us know if you need further assistance. As always we are happy to help you out. 
 
Regards, 
Lakshmi Natarajan 


Loader.
Up arrow icon