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

MikilllMikilll Member ✭✭✭

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.

Best Answers

  • JiriMatejkaJiriMatejka CZ ✭✭✭
    Accepted Answer

    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.

  • AlessandroCaliaroAlessandroCaliaro IT ✭✭✭✭✭
    Accepted Answer
    Use MessagingCenter. In OnResume send a message and subscribe to it in your viewmodel

Answers

  • JiriMatejkaJiriMatejka CZMember ✭✭✭
    Accepted Answer

    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.

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭
    Accepted Answer
    Use MessagingCenter. In OnResume send a message and subscribe to it in your viewmodel
Sign In or Register to comment.