xamlxamarin.formstoolbaritems

Xamarin.Forms: Not visible ToolbarItems in ContentPage


I am using Xamarin.Forms for my project & I need to have Toolbar at the top of the page. I am trying to get it along with Tabbed pages at bottom. My code is

<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:edTheSIS"
             x:Class="edTheSIS.ParentDashboard">
    <ContentPage.ToolbarItems>
        <ToolbarItem Name="MenuItem1" Order="Primary" Text="Item 1" Priority="0" />
        <ToolbarItem Name="MenuItem2" Order="Primary" Text="Item 2" Priority="1" />
    </ContentPage.ToolbarItems>
    <AbsoluteLayout>
        <StackLayout BackgroundColor="Teal" AbsoluteLayout.LayoutBounds="0, 5, 0, 0" AbsoluteLayout.LayoutFlags="All">
            <StackLayout Margin="0,200,0,0" HorizontalOptions="Center">
                <Label Text="Xamarin.Forms" HorizontalTextAlignment="Center" TextColor="White"></Label>
                <Label Text="Bottom NavigationBar" HorizontalTextAlignment="Center" TextColor="White"></Label>
            </StackLayout>
        </StackLayout>
        <StackLayout AbsoluteLayout.LayoutBounds=".20,1,1,.1" AbsoluteLayout.LayoutFlags="All" BackgroundColor="White" HorizontalOptions="FillAndExpand" Orientation="Horizontal">
            <StackLayout Style="{StaticResource ButtonNavigationBarStackLayoutStyle}" x:Name="stckHome">
                <Image Margin="0,10,0,10" x:Name="imgHome" Style="{StaticResource ButtonNavigationBarImageStyle}" />
                <Label Text="Dairy" Style="{StaticResource ButtonNavigationBarLabelStyle}"></Label>
            </StackLayout>
            <StackLayout Style="{StaticResource ButtonNavigationBarStackLayoutStyle}" x:Name="stckAlarm">
                <Image Margin="0,10,0,10" x:Name="imgAlarm" Style="{StaticResource ButtonNavigationBarImageStyle}" />
                <Label Text="Alarm" Style="{StaticResource ButtonNavigationBarLabelStyle}"></Label>
            </StackLayout>
        </StackLayout>
    </AbsoluteLayout>
</ContentPage>  

After executing the code only tabs are showing up, not ToolbarItems.


Solution

  • Wrap your page in a NavigationPage.

    I'm guessing you're setting your MainPage in the App.xaml.cs now like: MainPage = new ParentDashboard();

    Set this to be: MainPage = new NavigationPage(new ParentDashboard());