Reload screen after back action

ThePipihThePipih USMember, University

Hi all,

I'm editing some info in my Screen B and after press back button I have to reload previous Screen A but I don't want to override back button functionality.

Have you any idea to do this ??

Best Regards,

Posts

  • adamkempadamkemp USInsider, Developer Group Leader mod

    Bindings should handle this automatically. If you use bindings and INotifyPropertyChanged then you just have to update the view model or model. That's the recommended approach.

  • ThePipihThePipih USMember, University

    That's correct but what is the best way to update a previous view model or model ?
    I mean I don't have any reference to the previous view model in the new screen B so when I go back to Screen A I haven't the changes at view model level, Am I clear ??

    Thanks,

  • TorbenKruseTorbenKruse DEMember ✭✭✭

    Hi,

    I have a smiliar case. I don't know if this is the best approach but I handle it like this:

    • I have a View which displays some data from a REST service. This View has a static property named LoadOnAppearing. In the IsAppearing event of the View I make the call to the REST service to receive the data, when it's finished the LoadOnAppearing is set to false.

    • I have another View which displays some settings. These settings changing the result of the REST call, so I have to update the ViewModel of the previous View when coming back from the settings View. Therefore, when the user hits save, I set the LoadOnAppearing property to true before calling pop on the navigation stack. When the user hits cancel I just call pop.

    Does that help?

  • adamkempadamkemp USInsider, Developer Group Leader mod

    Static properties are not a good solution to this problem. Instead, when you create the view model for the second page you should give it a reference to the view model of the first page or use an event in the second page and attach to that event in the first page. If you are using something like Xamarin.Forms.Labs to do view model navigation with a factory then see this post to learn how to access the view model that is created for you.

Sign In or Register to comment.