Search code examples
c#windows-phone-8asynchronousobject-referencenavigationservice

how to retrieve the instance of library which is invoked using navigationservice.service () in wp8


I have created an authentication library in wp8 which requires me to provide a login screen UI and return the session id and other login details on authentication with server.. I have an API which returns the login data..

Now in the app im going to the login screen using NavigationService.navigate () which automatically instantiates my library class..

My Question is how do I get the reference to object of class that is instantiated by navigate method.. Also it seems that navigate() is asynchronous as it shows my login page and immediately moves to the line after the call.. My requirement is that I have to call the API that returns login data only after authentication has been performed but I have no reference of the instantiated object to call it

Is there any way to make the navigate() wait until the authentication is complete?


Solution

  • You are getting username and password from login screen and you are using this data for authentication.then,you can call your API in login screen's "say Login" button and after that you can use event delegate mechanism to receive web service response status, if its correct then you can navigate to next screen,till then you can use ProgressBar.

    please check this code to get understanding of await:

        Object response = await Authenticate(UsernameTextBox.Text, PasswdTextBox.Password);
    
        if (response is success)//typecast your object as per your need to get status of result
        {
          Navigate
        }
        else
        {
         Show error dialog
        }
    

    Also dont forget to modify your button event handler's signature with "async".