Xamarin.Forms:ContentPage 中不可见 ToolbarItems

Xamarin.Forms: Not visible ToolbarItems in ContentPage

我正在为我的项目使用 Xamarin.Forms,我需要在页面顶部有工具栏。 我正在尝试将其与底部的选项卡式页面一起使用。 我的密码是

<?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>  

执行代码后,只显示选项卡,不显示 ToolbarItems。

将您的页面包装成 NavigationPage

我猜你正在 App.xaml.cs 中设置你的 MainPage 现在像:MainPage = new ParentDashboard();

设置为:MainPage = new NavigationPage(new ParentDashboard());