Xamarin.forms Tabbed Page not showing in ios after PopAsync() - xamarin.forms

I have a xamarin.forms application which have a login screen and TabbedsPage as MainPage.
The navigation from login page to MainPage is like
Navigation.InsertPageBefore(new MainPage(), this);
await Navigation.PopAsync();
The problem I am facing is that Tabbed Page not showing in ios. It works fine in android. What will be the issue?

it would be much simpler to just assign the app's MainPage
Application.Current.MainPage = new MainPage();
This will replace LoginPage with MainPage. If you need Navigation, then wrap it in a NavigationPage
Application.Current.MainPage = new NavigationPage(new MainPage());

Related

How to Navigateback from Xamarin.Forms Prism Popup

Xamarin.forms using Prism Navigation back is not working in below scenario :
App.xaml.cs in OnInitialized NavigationService.NavigateAsync(nameof(LoginView));
In LoginViewModel once login I am navigating to MainPage await _navigationService.NavigateAsync(new Uri("MainPage", UriKind.Relative),useModalNavigation:true, animated: false);
MainPaga has a Button once I click in Button it will Popup setting Page navigation Popup like : await _navigationService.NavigateAsync(new Uri("SettingView", UriKind.Relative), useModalNavigation: true, animated: false);
SettingView(Popup) has a Button(LogOut) once I click on Button(LogOut) it has to go back in LoginView here is the code navigating back.
await _navigationService.ClearPopupStackAsync(animated: false);
await _navigationService.GoBackAsync(useModalNavigation: true, animated: false);
first I am Clearing Popup then navigating back, but it wont navigate back to LoginView?
If you are using PRISM and want to 'clear' the current stack.
You better use the explicit uri navigation.
Meaning the code behind the logout button should look like this
await _navigationService.NavigateAsync("/NavigationPage/LoginView");
By adding the / at the beginning of the URI, the current stack will be cleared.
You should just use absolute uri to set Loginpage as Mainpage after user confirm to logout like this
await NavigationService.NavigateAsync(new System.Uri("/LoginPage",System.UriKind.Absolute));

Xamarin embedded Forms ios has additional top bar

I have an IOS App with a Tabbar and an embedded Xamarin Forms Page with a listview.
This is the code used to embedd it:
contactListViewController = new Business.Views.ContactListView { BindingContext = ViewModel }.CreateViewController();
contactListViewController.WillMoveToParentViewController(this);
View.Add(contactListViewController.View);
AddChildViewController(contactListViewController);
contactListViewController.DidMoveToParentViewController(this);
The page is displayed correctly, but it does have an additional bar on the top.
How can I get rid of that? I tried to set it to hidden on the NavigationController. But it doesn't have one (NavigationController is always null).
How can I remove that bar?
The solution is, to hide the Navigationbar on the mainpage not the new added ViewController:
NavigationController.NavigationBarHidden = true;
// add subview.
activityViewController = new Business.Views.ActivityView { BindingContext = ViewModel }.CreateViewController();
activityViewController.WillMoveToParentViewController(this);
View.Add(activityViewController.View);
AddChildViewController(activityViewController);
activityViewController.DidMoveToParentViewController(this);

How do I close an MvvmCross MasterDetail page?

I would like my app to show a Login page, then a MasterDetail page with a 'hamburger' menu. On the hamburger menu I want a Log Out entry that closes the Master Detail and shows the Login page again. I have all but the log out part working.
I have copied code from the MvvmCross Playgrounds sample, specifically the MixedNavFirstPage (which fakes a login procedure), MixedNavMasterDetailPage (the 'hamburger menu'), and MixedNavMasterRootContentPage.
If I try to close the MixedNavMasterDetailPage with await _navigationService.Close(this) then I get a null reference exception in MvxFormsPagePresenter.CloseMasterDetailPage()
This question How to Exit (or Navigate out of )a MasterDetail page to a simple ContentPage in Xamarin. Forms? covers what I want to do in straight Xamarin.Forms, I'm just not sure how to do the equivalent in MvvmCross.
In your LoginPage add the MvxContentPagePresentation attribute NoHistory = true
Then simply navigate to the login page, and when the user has logged in, navigate to your MasterDetail page also with NoHistory = true.
When the user logs out again, simply navigate to your LoginPage, and as the NoHistory = true the MasterDetail will be removed completely.
[MvxContentPagePresentation(WrapInNavigationPage = false, NoHistory = true)]
public partial class LoginPage : MvxContentPage<LoginViewModel>
{
public LoginPage()
{
InitializeComponent();
}
}

Xamarin Forms Navigation in Modal Page

I have pushed a new ModalPage onto my current NavigationPage using await Navigation.PushModalAsync(new ProfilePage()); I cannot figure out how to create a NavigationPage inside the ModalPage. I want to load another page, wrapping inside a NavigationPage so that the loaded page has a navigation bar and back button to be able to return to the ModalPage (ProfilePage).
I am trying to achieve:
NavigationPage > ModalPage > New NavigationPage
I have tried creating a new NavigationPage inside the ModalPage and pushing the new page onto the NavigationPage but nothing happens. e.g.
var navigationPage = new NavigationPage(this);
navigationPage.PushAsync(new Page());
Can anyone help?
var page = new NavigationPage(new MyPage());
Navigation.PushModalAsync(page);

Using Tabbed Page with Master Detail page in Xamarin Forms

I am using MasterDetail page in xamarin forms, my detail page is a tabbed page with three tabs, my problem is when I am writing below code in MasterDetail Page to remove NavigationBar from that page
protected async override void OnAppearing ()
{
base.OnAppearing ();
NavigationPage.SetHasNavigationBar (this,false);
}
Then my tab page is not working properly like all tabs got disabled.
But without using this code everything is working fine.
But I need to write this code as I don't want that navigation bar on my master detail page.
You can hide the navigation bar by creating a new NavigationPage(new YourTabbedPage) and then you can use the code to hide the NavigationBar
NavigationPage.SetHasNavigationBar (this,false);
You can have different NavigationPage MainPage of your App.cs you can have an instance of your App.cs like this:
public static App Instance { get; private set; }
So now you can set:
App.Instance.MainPage = new NavigationPage(new YoutTabbedPage());
Hope this helps.

Resources