locked
Refresh a view model of a current page when app is moved from background to foreground RRS feed

  • Question

  • User369433 posted

    How can I refresh values in view model when the app is moved from background to foreground? I know that there is method onResume() in App.xaml.cs but that does not help much, because I don't have access from this method to my current view model.

    Saturday, December 1, 2018 8:26 PM

Answers

  • User235050 posted

    If you are using Master Detail navigation pattern you may use var currentPage = ((NavigationPage)((MasterDetailPage)Application.Current.MainPage).Detail).RootPage; to get the currently displayed page and probably the page has a reference to the view model.

    I think it's doable on when using other navigation patterns too.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Saturday, December 1, 2018 9:42 PM
  • User2148 posted

    Use MessagingCenter. In OnResume send a message and subscribe to it in your viewmodel

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Saturday, December 1, 2018 10:09 PM

All replies

  • User235050 posted

    If you are using Master Detail navigation pattern you may use var currentPage = ((NavigationPage)((MasterDetailPage)Application.Current.MainPage).Detail).RootPage; to get the currently displayed page and probably the page has a reference to the view model.

    I think it's doable on when using other navigation patterns too.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Saturday, December 1, 2018 9:42 PM
  • User2148 posted

    Use MessagingCenter. In OnResume send a message and subscribe to it in your viewmodel

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Saturday, December 1, 2018 10:09 PM