XAML 如何仅在特定页面上设置弹出菜单- .NET MAUI

xesrikrc  于 2023-01-06  发布在  .NET
关注(0)|答案(1)|浏览(315)

我正在制作的应用程序是一个提供食谱的应用程序。启动应用程序后,用户首先会看到登录页面,用户在登录页面输入数据并点击“登录”按钮后,会进入主页。在该页面上,有一些定义好的菜肴菜单,以及应该是什么菜单。即左上角的弹出菜单(作为navbar的一部分)但是没有这样的东西。唯一显示的是一个箭头,它将您带回到登录页面。我用元素定义了弹出按钮(开胃菜、主菜和甜点),并尝试添加属性,使弹出窗口在登录页面上不可见,而只有在登录后才可见。对于登录页面,我设法在Shell.FlyoutBehavior=“Disabled”属性的帮助下创建了它,但是对于主页的“Flyout”属性来说,这同样不起作用。
AppShell代码:

<Shell
    x:Class="ReceptiUI.AppShell"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:ReceptiUI"
    Shell.FlyoutItemIsVisible="True"
    Shell.FlyoutBehavior="Flyout">

<ShellContent
    Shell.FlyoutBehavior="Disabled"
    Title="Home"
    ContentTemplate="{DataTemplate local:Login}"
    Route="Login" />

<ShellContent
    Shell.FlyoutBehavior="Flyout"
    Title="Home"
    ContentTemplate="{DataTemplate local:MainPage}"
    Route="MainPage"/>

<FlyoutItem Title="Predjelo" Icon="breakfast.png">
   <ShellContent ContentTemplate="{DataTemplate local:Breakfast}"/>
</FlyoutItem>
<FlyoutItem Title="Glavno jelo" Icon="food.png">
    <ShellContent ContentTemplate="{DataTemplate local:Lunch}"/>
</FlyoutItem>
<FlyoutItem Title="Desert" Icon="dinner.png">
     <ShellContent ContentTemplate="{DataTemplate local:Dinner}"/>
</FlyoutItem>
<FlyoutItem Title="Meni" Icon="dinner.png">
    <ShellContent ContentTemplate="{DataTemplatelocal:ListaJela}"/>
</FlyoutItem>

我还在主页上设置了这些属性'Shell.FlyoutItemIsVisible =“True”' Shell.FlyoutBehavior =“Flyout”',但仍然没有弹出菜单。

46qrfjad

46qrfjad1#

您可以在主页中编写FlyoutPage,而不是使用AppShell中的shell弹出按钮。
下面是代码演示:

<FlyoutPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
            xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
            xmlns:local="clr-namespace:FlyoutPageNavigation"
            x:Class="FlyoutPageNavigation.MainPage">
    <FlyoutPage.Flyout>
        <local:FlyoutMenuPage x:Name="flyoutPage" />
    </FlyoutPage.Flyout>
    <FlyoutPage.Detail>
        <NavigationPage>
            <x:Arguments>
                <local:ContactsPage />
            </x:Arguments>
        </NavigationPage>
    </FlyoutPage.Detail>
</FlyoutPage>

在AppShell中,您只需编写一个普通的导航来从登录页导航到主页。

相关问题