I am using Xamarin Forms, added the below code for Toolbar, but it not showing on the right top (with 3 dots) and but I could see Menu when I use Menu hardware button on device.
Device running Android Jelly bean 4.3.
<ToolbarItem Text="QUICK LINKS" Activated="OnToolBarClick" Order="Secondary" Priority="0" />
Any suggestion?
Make sure that when you create the instance of the page containing the toolbar, you use the NavigationPage class to wrap it, otherwise the toolbar will not be displayed.
For example, assume UpdateScoresPage is the page with the toolbar in, and we're calling this from the parent page. If you omit new NavigationPage(page) the toolbar will not show.
UpdateScoresPage page = new UpdateScoresPage(Model, model);
await Navigation.PushModalAsync(new NavigationPage(page));
Related
With the standard (template) implementation of Master Detail Page, I do not get a back button when I call the side menu.
Standard implementation looks like this:
<NavigationPage>
<x:Arguments>
<local:DetailPage1/>
</x:Arguments>
</NavigationPage>
But when I implement navigation in this way:
MainPage = new NavigationPage(new MainPage());
i get the button back
Why does this happen and why I do not get a button with the standard (template) implementation? Thanks
screenshot with a running button at the bottom
enter image description here
First of all - the menu (master page) should not have a back button.
From the official documentation:
A MasterDetailPage is designed to be a root page, and using it as a
child page in other page types could result in unexpected and
inconsistent behavior. In addition, it's recommended that the master
page of a MasterDetailPage should always be a ContentPage instance,
and that the detail page should only be populated with TabbedPage,
NavigationPage, and ContentPage instances. This will help to ensure a
consistent user experience across all platforms.
If your MasterDetailPage is not a root page and it is wrapped by a NavigationPage you may see the back arrow.
That should answer your question. Additional details and restrictions are listed in the same official doc.
I have set up my Xamarin.Forms Prism application to use a Master-Detail Page (with MasterBehavior set to Popover) for its navigation, but I am noticing a few differences between my Prism app and the sample Xamarin.Forms app using this page (https://developer.xamarin.com/guides/xamarin-forms/user-interface/navigation/master-detail-page/).
On Android, clicking the hamburger icon makes the master slide out in both apps. In the sample app, the hamburger icon remains visible. In my Prism app, the hamburger icon does not remain visible, as the master view takes the full height of the screen, as shown below:
On UWP, clicking the hamburger icon makes the master slide out in both apps. In the sample app, the hamburger icon remains visible and the title of the master page is shown at the top. In my Prism app, neither of these items are visible, as shown below:
There also appears to be some type of padding or empty space at the top and bottom of the Prism app master view.
Are these differences introduced by Prism itself, or is there a way to configure the master to behave similar to the vanilla Xamarin.Forms sample?
UPDATED SCREENSHOTS
To better demonstrate the issue that I am seeing, here are some more screenshots.
Xamarin sample, app launch and then hitting the hamburger icon keeps the navigation bar (with hamburger icon) visible with the master visible:
My Prism app, app launch and then hitting the hamburger icon makes the master view take up the entire height of the screen:
In order to get the hamburger icon to show when you navigation to a page you have to wrap the Detail in a NavigationPage. So register the navigationPage for navigation, and then add it to your navigation URI.
protected override void OnInitialized()
{
NavigationService.NavigateAsync("MyMasterDetail/NavigationPage/MainPage");
}
Take a look at this sandbox example:
https://github.com/PrismLibrary/Prism/tree/master/Sandbox/Xamarin
I am trying to add a back button to the toolbar and I have read that it can be done using the following in the constructor
NavigationPage.SetHasBackButton(this,true);
I have also added the same in xaml in the ContentPage
NavigationPage.HasBackButton="True" NavigationPage.BackButtonTitle="Search"
but I cant see my title shown in the toolbar or the arrow for the back button. What am I doing wrong. Is this due to the fact that I am using FreshMVVM
I have got it working now,I was loading the page as a modal and the back button was not showing. Loading the page as a non modal did the trick. However the title of the back button seems to say 'Back' somehow even after specifying a value for the title
Update
The title of the previous page was not set , setting it to a value changes the title of the back button to be the same. I thought we could enforce the back button to have a different value through the call from the constructor but that didnt work for me
Have a look at this post by James Montemagno. In XAML add the NavigationPage.BackButtonTitle to the ContentPage. Remember this is set on the page you want to navigate back to, not on the page currently displayed. I'm using this with a FreshMvvm project.
<ContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
ios:Page.UseSafeArea="true"
x:Class="MyProject.Pages.MyPage"
NavigationPage.BackButtonTitle="Back"
Title="My Page Title">
...
</ContentPage>
I would like to create context menu in my project. On android it's called PopupMenu. On click of button, I have to show the popup with 3 rows and it's clickable event. How I can implement this in my code? Example of this menu here:
http://www.javatpoint.com/images/androidimages/popup2.png
The Xamarin.Forms way to handle this is to call DisplayActionSheet() on the Page.
It's not exactly a popup, but on the other hand it has better chances to be fully displayed and visible on screen if your view can scroll.
I have an application with a lot of screens, let say HomePage, Section Screen and Detail Page, Category Screen.
I use a NavigationController to Navigate from HomePage to Section Screen.
In the SectionScreen I have used a SideBarController component (https://components.xamarin.com/view/sidebarnavigation) to implement a navigation drawer or a flyout menu.
The problem is how to navigate from Section Screen to Detail Page or to Category Screen. I need to make this kind of navigation from MenuController or ContentController.
I don't want to just change the contentView. I want to push another UIViewController.
I have used the usual one:
this.NavigationController.PushViewController( new UIViewControllerExample(), true);
but there are some problems:
In the details page I can't access the NavigationBar
When I press back, the app crashes with an error:
Cant add self to subview
This is how to it should look like.
This is the problem. The first image display what happen when i use the above code,
Any idea how to solve this.
as you can find in that page of component you should use SidebarController as your navigationcontroller
SidebarController.ChangeContentView(new OtherContentController());