I am currently developing app using Xamarin.Forms. I am facing some serious issue in iOS. My root page is TabbedPage and I want to make my tabs visible for entire applications. Hence I am setting MainPage as below
App.cs
MainPage = new NavigationPage(new MyTabbedPage());
MyTabbedPage.cs
Children.Add(new NavigationPage(new FirstTabbedPage()));
Children.Add(new NavigationPage(new SecondTabbedPage()));
Children.Add(new NavigationPage(new ThirdTabbedPage()));
Both FirstTabbedPage & SecondTabbedPage shows DataGrid using DevExpress.Mobile. On tap of any row from the Grid I am Navigating to another ContentPage say MyContentPage within the Root Tab.
SecondTabbePage.cs
private async void Grid_RowTap(object sender, RowTapEventArgs e)
{
//Some code logic, to get data from server
await Navigation.PushAsync(new MyContentPage());
}
For Example I am navigating to MyContentPage from SecondTabbedPage. From ContentPage I am Navigating to FirstTabbedPage. Now if I click SecondTabbedPage, MyContentPage will be shown, but I don't want this behaviour hence I am removing the page from NavigationStack in OnDisappearing method of MyContentPage as below:
MyContentPage.cs
protected override void OnDisappearing()
{
base.OnDisappearing();
//Clear Navigation Stack, clicking on tab page should always
//go to corresponding page
try
{
var existingPages = Navigation.NavigationStack.ToList();
foreach (var page in existingPages)
{
//existingPages count should be greater than 1, so that this will never be root page. Otherwise removing root page will throw exception
if (string.Compare(page.GetType().Name, "MyContentPage", StringComparison.OrdinalIgnoreCase) == 0 && existingPages.Count > 1)
{
Navigation.RemovePage(page);
}
}
//Just to check whether page was removed or not, but still was able to see MyContentPage even after removing it from Navigation Stack
var existingPages = Navigation.NavigationStack.ToList();
}
catch(Exception ex)
{
}
}
Now the issues are:
- Even after calling RemovePage(MyContentPage) I am able to see that page in Debug mode.
- Due to this behaviour await Navigation.PushAsync(new MyContentPage()); is not navigating to MyContentPage second time even-though it executes code without any exception.
The same code is working fine in Android as Android life cycle is different which I was able to see in Debug mode
Few Things I Tried Are:
- Removed NavigationPage from MainPage (TabbedPage) as I read that TabbedPage inside NavigationPage is not good design for iOS.
- Removed NavigationPage on Child Items but tabbed icons were not shown after navigating to MyContentPage
- Tried removing MyContentPage from NavigationStack in OnAppearing event of FirstTabbedPage.