Xamarin embedded Forms ios has additional top bar - xamarin.forms

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);

Related

xamarin.forms adding layouts from code only works once when cleared

I have an empty layout in xaml.
I add a view to it:
layout_secondLayout.Children.Clear();
layout_secondLayout.InputTransparent = false;
layout_secondLayout.Children.Add(new Page_SubCategories(Helpers.CategoriesEnum.food, AppResources.FoodAndDrink));
layout_secondLayout.IsVisible = true;
When the user clicks back, i disable the layouts children:
layout_secondLayout.Children.Clear();
layout_secondLayout.IsVisible = false;
layout_secondLayout.InputTransparent = true;
When I now however call the upper method again to add another layout to the now again empty layout, it just doesnt react upon first click. If I click another time, the layout is shown, but twice ( as it now has 2 children.)
Why is that?

iOS 13 and UiSplitViewController when presenting in Portrait missing DisplayMode Button

I have the same issue as described here
UISplitViewController portrait mode missing UIBarButtonItem
my SplitView contains two NavigationControllers which each contains TableViewController
the Detail tableview controller is the split views delegate there all generated in code
and have a delegate method splitViewController:willChangeToDisplayMode:
and splitViewController:willHideViewController:withBarButtonItem:forPopoverController:
for good measure
I have even tried to add the button my self if it is not there in splitViewController:willChangeToDisplayMode:
still no luck
any suggestions ?
Regards Christian
I Coded around the issue bu putting come code splitViewController:willChangeToDisplayMode: if the display mode is PrimaryHidden and the detail view controller don't contain a the splits view displauModeButtonItem in topmost navigationItem if the detail view controllers leftBarButtonsItems the I just manually add it
This is basically what #canderse said but I am showing the code. There is also a trick if you want your button to have a title. In your DetailViewController override the following method:
-(void)splitViewController:(UISplitViewController *)svc willChangeToDisplayMode:(UISplitViewControllerDisplayMode)displayMode{
//fix for missing navigation button
if(displayMode == UISplitViewControllerDisplayModePrimaryHidden){
self.navigationItem.leftItemsSupplementBackButton = true;
UIBarButtonItem *item=[svc displayModeButtonItem];
[self.navigationItem setLeftBarButtonItem:item animated:YES];
}}
For the button to have title, set your master view controller's title in awakeFromNib:
self.title = NSLocalizedString(#"Title", #"Title");
If you try to set the title in willChangeToDisplayMode, it won't work.

Xamarin.Forms: How to navigate to TabbedPage's child page

I meet a scenario to navigate from MyTabbedPage/ChildTabPage1/Page1 to MyTabbedPage/ChildTabPage2/Page2 in Xamarin.Forms
Right now, I can only switch between MyTabbedPage/ChildTabPage1 and MyTabbedPage/ChildTabPage2. But I need to navigate directly from MyTabbedPage/ChildTabPage1/Page1 to MyTabbedPage/ChildTabPage2/Page2
How to achieve this?
Thank you very much in advance for your helps.
You can try something like this.
public App()
{
InitializeComponent();
var parentPage = new MasterDetailView(); // name of the master detail page
parentPage.IsPresented = false;
var tabbedPage = new MasterDetailTabbedPage(); // name of the tabbed page
tabbedPage.CurrentPage = tabbedPage.Children[2]; // specify the index of the tab
parentPage.Detail = new NavigationPage(tabbedPage); // assign the tabbed page to master detail page
MainPage = parentPage; // navigate to master detail page (3rd tab selected)
}
If you want to navigate MyTabbedPage/ChildTabPage1/Page1 to MyTabbedPage/ChildTabPage2/Page2 in Xamarin.Forms, I suggest you can consider to use Shell to do this.
Xamarin.Forms Shell includes a URI-based navigation experience that uses routes to navigate to any page in the application, without having to follow a set navigation hierarchy. In addition, it also provides the ability to navigate backwards without having to visit all of the pages on the navigation stack.
Here is the article about using Shell:https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/shell/navigation

Xamarin.Forms, using the Prism.Forms NavigationService

I am trying to implement a login scenario with Xamarin Forms and Prism.
My application root page is a MasterDetail page (HomeMasterDetailPage); this being used to provide the side menu.
What I am trying to do is to have the HomeMasterDetailPage page shown with Content set to an instance of LoginPage. When the user logs in, the Content should change to an instance of HomeDetailContentPage. It should not be possible to return to the LoginPage using the back button.
I am using the NavigationService from Prism Forms.
My start up is like this...
public partial class App : PrismApplication {
public App(IPlatformInitializer initializer = null)
: base(initializer) {
}
protected override void OnInitialized() {
InitializeComponent();
Uri uri = new Uri($"/{nameof(NavigationPage)}/{nameof(HomeMasterDetailPage)}/{nameof(HomeDetailContentPage)}", UriKind.Absolute);
var settings = Container.Resolve<SettingsService>();
if (!settings.DeviceUserID.HasValue)
uri = new Uri($"/{nameof(NavigationPage)}/{nameof(HomeMasterDetailPage)}/{nameof(LoginPage)}", UriKind.Absolute);
NavigationService.NavigateAsync(uri);
}
protected override void RegisterTypes() {
Container.RegisterTypeForNavigation<NavigationPage>();
Container.RegisterTypeForNavigation<LoginPage, LoginPageViewModel>();
Container.RegisterTypeForNavigation<HomeMasterDetailPage, HomePageViewModel>();
Container.RegisterTypeForNavigation<HomeMasterContentPage>();
Container.RegisterTypeForNavigation<HomeDetailContentPage>();
}
}
This correctly displays the LoginPage within the HomeMasterDetailPage if the user is not already logged on, and the HomeDetailContentPage within the same HomeMasterDetailPage if the user is logged on.
The problem comes when actually logging on; the following is the code within the view model for the LoginPage...
protected async Task ExecuteLoginCommand() {
Uri uri = new Uri($"/{nameof(NavigationPage)}/{nameof(HomeMasterDetailPage)}/{nameof(HomeDetailContentPage)}", UriKind.Absolute);
await this.navigationService.NavigateAsync(uri);
}
It is my understanding that by using an absolute Uri this should reset the navigation so that the new page arrangement (/NavigationPage/HomeMasterDetailPage/HomeDetailContentPage) is at the top and bottom of the stack, allowing me to then move forward from there. Instead, I am getting an unhandled exception (on Android 7.0).
What am I doing wrong?
Note: All of the examples that I see have the MasterDetailPage at the root with Content being set to NavigationPage/ContentPage; when I try this I do not get exceptions, however the side menu operates differently within the MasterDetailPage - when you tap on the "hamburger" the side menu slides in over everything (including the action/title bar) and the only way to clear it is to tap outside of the side menu that slides in whereas when I show the MasterDetailPage within a NavigationPage the side menu slides in below the action/title bar and the hamburger changes to an arrow that you can click to hide the side menu again.
I can't say I've tested this exact scenario. However, if your LoginPage is the Detail of a MasterDetailPage, you may not want to perform the navigation from the LoginPage. You could, instead create a SuccessfulLoginEvent, which you would then publish from the LoginPage using the IEventAggregator, and you would subscribe to on your MasterDetailPage's ViewModel. You could then perform the navigation as _navigationService.NavigateAsync("NavigationPage/ViewA") and it should reset the Detail such that the back button doesn't bring you to the LoginPage.
Alternatively, you can simply perform an absolute Navigation which has the effect of:
Application.Current.MainPage = new MyPage().
To do to this, you could do the navigation from anywhere as:
_navigationService.NavigateAsync("/MyMasterDetailPage/NavigationPage/ViewA")

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