Reputation: 1381
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,
Upvotes: 1
Views: 90
Reputation: 1697
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));
Upvotes: 0