Forum Xamarin.Forms

after PopAsync Reload list

So I have a page with a list that pulls data from the database, then I navigate to another page that adds something to the database, then I pop back to the previous page but want to run the refresh command to pull from the database again.

I can't figure out how to do this. Any ideas?
Thank you!

ps. I'm new to MVVM so please be gentle...

Tagged:

Posts

  • BrianMBrianM USMember ✭✭

    Override the OnAppearing event and refresh there.

    protected override void OnAppearing()
    {
    base.OnAppearing();

            // Refresh here
        }
    
  • ScottVentsUSScottVentsUS Member ✭✭

    @BrianM said:
    Override the OnAppearing event and refresh there.

    protected override void OnAppearing()
    {
    base.OnAppearing();

            // Refresh here
        }
    

    I would, but I'm trying to keep things in the view model. Currently I have a method in the viewmodel "PopulateList()" I'd like that to run on appearing. I would just run an execute, but the viewmodel takes parameters from the previous viewmodel. Maybe I'm not passing things between viewmodels properly, but it's the only way I know how to do it.
    Thanks.

  • ScottVentsUSScottVentsUS Member ✭✭

    bump :)

  • JohnHJohnH GBMember ✭✭✭✭✭
    What is wrong with using OnAppearing to let your view model know it needs to reload the list?
  • ScottVentsUSScottVentsUS Member ✭✭

    @JohnH said:
    What is wrong with using OnAppearing to let your view model know it needs to reload the list?

    the way I have it set up, the viewmodel takes in parameters. Maybe there's a way to do it, if so I'm all ears.
    Thanks

  • JohnHJohnH GBMember ✭✭✭✭✭
    Why does it take parameters? The vm should already know it’s state. The view should just tell the vm that it should refresh, not what to refresh with.
  • ScottVentsUSScottVentsUS Member ✭✭

    Well, basically, it's a program that needs to be signed into, it's passing the current username of who is logged in for keeping track in the database.
    I am new to MVVM, maybe you have a better idea on how i could do this?

    Thanks

  • JohnHJohnH GBMember ✭✭✭✭✭

    I see, so your text entries should be bound to properties on your vm. Then your vm contains all of its state.

    There are quite a few examples of MVVM with Xamarin.Forms available, it might be best to start there.

  • ScottVentsUSScottVentsUS Member ✭✭
    edited October 2020

    I have everything bound into the VMs, and I do all database stuff and basically everything in the vm. but I don't really know what else to do. So I just passed with the pushasync like this: Application.Current.MainPage.Navigation.PushAsync(new frmAdmin(strCurrentUser));

  • JohnHJohnH GBMember ✭✭✭✭✭

    If you have everything already bound, then you already have the properties for your PopulateList method, no?

    As I said, take a look at the examples, they should help you understand how it all works.

  • ScottVentsUSScottVentsUS Member ✭✭

    I'll look into it! I may ask questions after I read them tomorrow. Thanks for your help!

Sign In or Register to comment.