【问题标题】:Xamarin.Forms: Not visible ToolbarItems in ContentPageXamarin.Forms:在 ContentPage 中不可见 ToolbarItems
【发布时间】:2018-08-20 02:32:13
【问题描述】:

我正在为我的项目使用 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。

【问题讨论】:

    标签: xaml xamarin.forms toolbaritems


    【解决方案1】:

    将您的页面包装在 NavigationPage 中。

    我猜你现在将MainPage 设置在App.xaml.cs 中,例如:MainPage = new ParentDashboard();

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

    【讨论】:

    • 正如你所说,我将MainPage 保留为ParentDashboard() 并获得ToolbarItems,但现在我没有获得登录页面,这是我的应用程序的第一页。我在MainPage.xaml 有登录用户界面。
    • 然后,每当您从登录页面切换到仪表板页面时,将其包装在 NavigationPage 中。
    • 我明白了。你是天才。
    猜你喜欢
    • 2019-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-22
    • 2021-02-21
    • 1970-01-01
    • 2016-01-22
    • 2018-11-10
    相关资源
    最近更新 更多