1

I have a MVVVM app with a view model that uses Hammock .

I call my Get2 function in the code behind my main page like this:

 private void List2_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
    {
        if (List2.SelectedItem != null)
        {
            ((MainPageViewModel)DataContext).Get2();

            NavigationService.Navigate(new Uri("/Page3.xaml", UriKind.Relative));
        }
    }

Here is my Get2 Function:

public void Get2()
{
    [...]

    restClient.BeginRequest(restRequest, Get2CallBack);
}

private void GetListStatusesCallBack(RestRequest Request, RestResponse Response, object Obj)
{ 
    [...]
}

But what happens at the end of my Get2() function is that instead of reaching the callback function just after , it goes back to my MainPage code behind, executs the NavigationService.Navigate(new Uri("/Page3.xaml", UriKind.Relative)); , quits the List2_SelectionChanged_1 and then reaches the CallBack function finally .

How come my CallBack Function is not reached just after Get2() ?

I would like the CallBack to be reached before the Navigation Event,

Daniel F. Thornton
  • 3,687
  • 2
  • 28
  • 41
user2505650
  • 1,293
  • 6
  • 20
  • 38

1 Answers1

0

Your method should be a Synchronous call. The behavior that you are describing requires the use of a Synchronous call.

However, looking at your code, the call looks to be async (BeginRequest).

Perhaps if you could post more details about the variable restClient (Datatype, intended usage etc.) it would be helpful.

Alternatively, you could try having this line in the call back method

NavigationService.Navigate(new Uri("/Page3.xaml", UriKind.Relative));
cvraman
  • 1,687
  • 1
  • 12
  • 18
  • i tried this but as the callback is in a c# class file i can't use the NavigationService – user2505650 Feb 23 '14 at 17:57
  • You should be able to add a reference to PresentationFramework.dll to the project that contains the C# class file. Then you should be able to use NavigationService. – cvraman Feb 23 '14 at 17:59