Getting control after INavigation.PopAsync() in Xamarin Forms

I have PageA + ViewModelA, and PageB + ViewModelB.

From A i'm calling PushAsync(B), editing some data, and calling PopAsync().

So now B becomes closed, and user returns to A.

But in B user changed some state, that should be update on A. What is the correct way to notify A to update state (and it would be better to have access to ViewModelB).

Best Answer


  • adamkempadamkemp USInsider, Developer Group Leader mod

    B should update the state in an object that A uses. For instance, you could give a reference to ViewModelA to ViewModelB. You could also just have a shared model object that both ViewModelA and ViewModelB have access to.

  • AdamWolfAdamWolf USMember, University ✭✭
    edited November 2015

    @deeptowncitizen you can also use the Xamarin.Forms Message Center. ViewModelB can send an ModelUpdatedMessage and ViewModelA can listen for that message.

    Here is the Message Center docs:

    If this or @adamkemp response answered your question please mark it as answered.

  • SreeeeSreeee INMember ✭✭✭✭✭

    Update: When subscribe use pageA.

    MessagingCenter.Subscribe<PageA>(this, "Refresh", (sender) =>
               //Call your show data method again
Sign In or Register to comment.