Prism Xamarin Forms ToolbarItem appearing twice - xamarin

I am using Prism for Xamarin Forms application development.
May be because I am new to both Prism and Xamarin Froms because of which I am facing a basic issue with the navigation.
Let me start with the details of my implementation and then the issue at hand.
I have a MasterDetail Page (named Home) which is my main page.
There are a few menu items in the Master Page. One of them is Partner.
On Click of Partner menu item, NavigationService.NavigateAsync("Navigation/Partner") method is called. Where "NavigationService" is of type "INavigationService".
This opens a page called "Partner" which is a tabbed page (TabbedPage). The first tab is a contentpage called "PartnerAll".
PartnerAll page contains a listview. On click of a list view item, a new page is opened "PartnerDetails" by calling NavigationService.NavigateAsync("Navigation/PartnerDetails", parameters, false, true);
On PartnerDetails page, I have added a toolbaritem called "Cancel".
Issue: When "PartnerDetails" page opens up, "Cancel" item shows up twice, as shown in the screenshot:
screenshot of partner details page with two cancel buttons
Where is it I am going wrong. What should I do to make it work?
Please assist.
Best regards, Ankur Jain

You’re pushing two NavigationPage’s onto the Navigation Stack. This would result in two Navigation bars. You can see in your screenshot you have both a back and a hamburger menu icon.

You should just pass in the identifier string for your destination page, instead of pushing another instance of the NavigationPage onto the stack
do it like so NavigationService.NavigateAsync(PartnerDetails);

Related

Prism Navigation keep MasterPageDetail menu after navigating to other page

I'm using prism and had a MasterDetailPage with some pages that is accessible from that. But, in some of this pages, I can navigate to other pages that is not accessible from the MasterPageDetail Menu, but menu is still accessible with sliding action. I'll post some prints to try explain.
That's is a page that is accessible from MasterPageDetailMenu
When the user is accessing this page, he can access the MasterPageDetail Menu. But if the user select an item of the list or click in "Plus" Floating Button, the app navigate to other Page where MasterPageDetail Menu shouldn't be accessible.
But, as you can see on the next image, if the user slide the page from the left to right, the MasterPageDetail Menu is still accessible
How can I avoid this behaviour?
In the App class, my code for navigate to MasterPageDetail is:
await NavigationService.NavigateAsync("Menu/Navigation/TipoItensCardapio")
In this case, menu is my MasterPagelDetail.
The code for navigate from TipoItensCardapio page to the second page is:
NavigationService.NavigateAsync("TipoItemCardapioEdit");
If you intend for a specific page to not allow the drawer to be swiped out it sounds like you should probably be pushing it as a Modal instead of a normal Page. For example:
await Navigation.PushModalAsync(new YourPage());
For more info about Xamarin.Forms modals I'd check out the docs

Xamarin Forms: Single button that opens a dropdown menu

Hi does anybody knows if I can make a button in Xamarin Forms that opens a small dropdown menu? I did this in android studio but I can't find a way how this could work in Xamarin.
It should look like this:
And like this if the button is clicked:
And the Button should not be in the navigation bar because this page don't have one.
So if anybody could help me I would be very grateful and sorry for my bad english.
The closest API in Xamarin that does that is to display a pop-up using DisplayActionSheet, but the dropdown menu will be at the bottom of the screen. Or you can use a Picker (link to documentation).
If you want to implement something that look exactly like the image in your post, you can create a StackLayout that contains a few buttons, and show it when the drop down menu button is clicked.
i think that you can do it not directly but if we let some things be together we can achieve it, you have to add toolbar item for the button and for the menu list it's a popup page that has transparent background and list menu on the top right !

How do you navigate Xamarin Forms using Prism from Master Detail to Content Page without Master Detail

I am using Xamarin Forms with Prism. How do you navigate from the MasterDetail.Master to a ContentPage that is not part of the MasterDetail (that is, I don't want to just update the detail and continue to be part of the Master/Detail relationship)? The use case is like the Gmail app when you click on Settings from the Hamburger menu. It takes you out of the Master/Detail and you are now in a NavigationPage/ContentPage with a back button to get back to the MasterDetail page.
If you were not using Prism you could go to the Detail page and do a Navigation.PushAsync from there:
var mdp = Application.Current.MainPage as MasterDetailPage;
mdp.IsPresented = false;
await mdp.Detail.Navigation.PushAsync(new ContentPage2());
But I don't see how to do this using Prism navigation.
-Steve
Assuming your Application.Current.MainPage is a MasterDetailPage. Current Detail in the MasterDetailPage is NavigationPage(new ContentPage1()).
In your ContentPage1, you have 2 options to navigate to ContentPage2:
Option 1: Show ContentPage2 in current navigation stack
You will be pushing ContentPage2 into the same Navigation stack of ContentPage1. Back button in navigation bar will be added automatically.
// Call this code in ContentPage1
_navigationService.PushAsync("ContentPage2");
Option 2: Show ContentPage2 modally
You are presenting the page modally and in a completely new navigation stack. You will need to add Back button in the NavigationBar and handle the click event with your own code.
// Call this code in ContentPage1
_navigationService.PushAsync("NavigationPage/ContentPage2", null, true);

Xamarin Forms NavigationPage showing multiple back buttons

I have several navigation pages that go several levels deep. Each time the user navigates to another page, an additional Back button is added to the top.
Navigation.PushAsync(new NavigationPage(new SettingsPage()));
Do I have to manually turn off the navigation bar prior to Pushing the new page or is there some type of setting for this?
Thanks.
Like Sushi mentioned in the comment, you're already in navigation page, you do not have to push a new NavigationPage every time.
Just use:
Navigation.PushAsync(new SettingsPage());
You can read more about navigation in Xamarin.Forms here: https://developer.xamarin.com/guides/xamarin-forms/user-interface/navigation/hierarchical/

How do I add an "add" button to a tab in a uitableviewcontroller within a uitabbarcontroller?

xcode 4.6
using Storyboards
When I drag a Bar Button Item to the navigation bar at the top of one of the UITableViewControllers that are children of the UITabBarController xcode creates a new navigation bar at the bottom of the page instead of adding the button where I dropped it. I would be ok with this, but when I run the app the bottom navigation bar never shows up, so my button is never displayed.
If you need to visualize the app, picture the following: Root controller displays a list of accounts. When an account is clicked a tab controller lists tabs for opportunities and contacts. I need the ability to add opportunities and contacts from the relevant tab
Any help is greatly appreciated.
EDIT
I am not sure if this is the correct solution or not. I have embedded the uitableviewcontrollers in navigation controllers, which appears to have fixed the problem.
Follow-up question - Is this the correct way to handle this situation?
Yes, that is the correct way to handle this situation.
You should embed the view controller inside a navigation controller by clicking the view controller in your storyboard and using the Xcode menu "Editor" > "Embed In" > "Navigation Controller".

Resources