Search code examples
c#data-bindingmauimobile-development

No Data Context Found For Binding in MAUI


I have a page to manage the data packets and in this page i have created a collection view part to view all the data s. But when i try to bind the viewer data, program says that there is no data context.

Here`s the code of the page in xaml: <CollectionView ItemsSource="{Binding PacketModels}">

And here is the code that i`m trying to bind it in my view model in C#:

           public sealed class ManageDataPacketsViewModel 
{

    public ObservableCollection<PacketModel> PacketModels
    {
        get { return MainDb.Instance.PacketCache; }
    }

    //public ObservableCollection<PacketModel> PacketModels => MainDb.Instance.PacketCache;

    public ManageDataPacketsViewModel()
    {
    }
}

Solution

  • I needed to refresh the packages every time we got a new one. So the code should be like this.

     public ManageDataPacketsViewModel()
        {
            MainDb.Instance.RefreshDataPacketCache();
        }