Hi,
I am working on sample application using Xamarin.Forms (MVVM Pattern logic) with PCL (httpclient).
I have designed the sample application with below scenario as "LoginPage(ContentPage) -> TabbedPage ->Children(ContentPage) with two view models(Filter,Search) "
Login Page: Root page to the application and user information validated and navigated to Next screen.
Search Calls Page: Tabbed page Contains two Children Tabs Named "Filter and Search'.
Filter tab contains picker control like 'Call Status,Call Assigned person,Team Details'.
Search tab will list the records based on the filter tab selection.
This sample application is working fine with "Android & iOS platform". When checking the sample application with Windows Phone platform , we are getting the below mentioned error for Asynchronous method and Tabbed children page loading.
My App.cs File
public class App
{
public static Page GetMainPage()
{
try
{
var rootPage = new NavigationPage(new **LoginPage()**);
Navigation = rootPage.Navigation;
return rootPage;
}
catch (Exception e) { }
}
}
My TabbedPage xaml file
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="eFACiLiTY.Views.SearchRequestTabPage"
xmlns:local="clr-namespace:Test.Views;assembly=Test" Title="Search Request">
**<TabbedPage.Children>
<local:SearchreqFilter />
<local:SearchreqSearch />
</TabbedPage.Children>**
</TabbedPage>
Here I am loading the TabPages(Filter and Search) with model data corresponding to ViewModels from WCF Rest service.
ViewModel: 1. SearchreqFilterViewModel 2. SearchreqListViewModel
I am calling LoadData()method in SearchreqFilterViewModel constructor which has an async method.
public class SearchreqFilterViewModel:INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public SearchreqFilterViewModel()
{
try
{
LoadSite(); //async await is used but LoadCallstatus function is called without waitng for the LoadSite() method output from WCF Service
LoadCallStatus();
}
catch(ex e) { }
}
public async void LoadSite()
{
try
{
object[] Parameters = new object[1];
Parameters[0] =test
_myDeserializedObjList_siteName = await Service.GetUsersite(Parameters); // here the function is not awaited for the output data from WCF Service and calls asynchronously next function
}
catch(Ex e) { }
}
public async void LoadCallStatus()
{
try
{
object[] Parameters = new object[1];
Parameters[0] = **_myDeserializedObjList_siteName[0].Sitename;**
myDeserializedObjList_callStatus = await Service.FillCallStatus(Parameters);
}
catch(Ex e) { }
}
kindly guide me to resolve the below issues in my sample application.
The problem is when calling SearchreqFilterViewModel constructor, LoadSite & LoadCallStatus methods called asynchronously without waiting for the method output. How to await the for LoadSite method output to proceed LoadCallStatus method?
While Loading the Tabbedpage control , Tabbed Children page calls the view models named (SearchreqFilterViewModel, SearchreqListViewModel) asynchronously . How to control calling the Tabbed children page one by one ( by finishing the first children view model functions and call next children page) ?
Thanks in advance.