3
votes

I have a service called AuthHelper, from which I take care of all of my application's navigation based on authentication status. In order to call the push or pop navigation methods on the navigation stacks I am using, I need to have access to a PageModel's CoreMethods object.

I have made this work by just passing the CoreMethods object in to every AuthHelper method which requires it. It would be more convenient, however, to just get the current FreshMVVM PageModel in the AuthHelper and derive the CoreMethods object from that.

I thought I had found what I was looking for in the Application.Current.MainPage.GetModel() FreshMVVM extension method. However it looks like that is not working because Application.Current.MainPage is referring to the navigation container I am using (the type of container changes depending on the application's current authentication status) instead of the current page, which is required by the GetModel() method.

Is there any way to get the current PageModel, more specifically the CoreMethods object, from a helper service without passing it as a parameter?

1

1 Answers

0
votes

In the past I have passed in the CoreMethods instance when I am in that situation, however have you tried Application.Current.MainPage.CurrentPage where the CoreMethods are on that CurrentPage?