如何在 ContentPage 和 FlyoutPage 之间切换。

huangapple go评论63阅读模式
英文:

How to change between a ContentPage to a FlyoutPage

问题

I want to develop a mobile application and the first page should be a Login page. When the user has been logged, I want to show a FlyoutPage with different options, but my problem is when I use NavigationPage to change from the login page to the FlyoutPage, the system hides the FlyoutPage menu options and shows the back button.

This is the login page.

如何在 ContentPage 和 FlyoutPage 之间切换。

.

如何在 ContentPage 和 FlyoutPage 之间切换。

如何在 ContentPage 和 FlyoutPage 之间切换。
如何在 ContentPage 和 FlyoutPage 之间切换。

英文:

I want to develop a mobile application and the first page should be a Login page. When de user has been logged, I want to show a FlyoutPage with differents options, but my problem is when I use NavigationPage to change from the login page to the FlyoutPage the system hides the FlyoutPage menu options and shows the back button.

This is the login page.

如何在 ContentPage 和 FlyoutPage 之间切换。

.

如何在 ContentPage 和 FlyoutPage 之间切换。

如何在 ContentPage 和 FlyoutPage 之间切换。
如何在 ContentPage 和 FlyoutPage 之间切换。

答案1

得分: 0

你可以使用 AppShell。尝试这样做:

AppShell.xaml

<Shell x:Class="mycompany.AppShell"
    xmlns:pages="clr-namespace:mycompany.Pages"
    xmlns:mycompany="clr-namespace:mycompany"
    x:DataType="mycompany:AppShell"
    FlyoutBehavior="Flyout">

    <FlyoutItem Title="主页">
        <Tab Title="标签1">
           <ShellContent ContentTemplate="{DataTemplate pages:AboutPage}"/>
        </Tab>

        <Tab Title="标签2">
            <ShellContent ContentTemplate="{DataTemplate pages:HomePage}"/>
        </Tab>
    </FlyoutItem>

    <FlyoutItem Title="选项1">
        <ShellContent ContentTemplate="{DataTemplate pages:ItemPage}"/>
    </FlyoutItem>

    <FlyoutItem Title="关于">
        <ShellContent ContentTemplate="{DataTemplate pages:AboutPage}"/>
    </FlyoutItem>

</Shell>

在 AppShell.xaml.cs

public AppShell()
{
    InitializeComponent();
    
    // 如果需要,跳转到登录页
    Navigation.PushAsync(new LoginPage());
}

在 LoginPage.xaml.cs

public LoginPage()
{
	InitializeComponent();
    
    // 隐藏底部标签栏
    Shell.SetTabBarIsVisible(this, false);
}

在 LoginPage.xaml 中隐藏顶部导航:

<ContentPage Shell.NavBarIsVisible="false">

</ContentPage>

最后一步是导航回 Shell 标签页,最佳位置是在 LoginPage 的 ViewModel 中,完成登录流程并导航到主屏幕。

Task.Run(async () =>
{
  // 导航回主 Shell 页面,包含标签和侧边菜单
  await Shell.Current.Navigation.PopToRootAsync();
});

希望对你有所帮助。

英文:

You can use AppShell. Try this:

AppShell.xaml

&lt;Shell x:Class=&quot;mycompany.AppShell&quot;
    xmlns:pages=&quot;clr-namespace:mycompany.Pages&quot;
    xmlns:mycompany=&quot;clr-namespace:mycompany&quot;
    x:DataType=&quot;mycompany:AppShell&quot;
    FlyoutBehavior=&quot;Flyout&quot;&gt;

    &lt;FlyoutItem Title=&quot;HOME&quot;&gt;
        &lt;Tab Title=&quot;tab1&quot;&gt;
           &lt;ShellContent ContentTemplate=&quot;{DataTemplate pages:AboutPage}&quot;/&gt;
        &lt;/Tab&gt;

        &lt;Tab Title=&quot;tab2&quot;&gt;
            &lt;ShellContent ContentTemplate=&quot;{DataTemplate pages:HomePage}&quot;/&gt;
        &lt;/Tab&gt;

    &lt;/FlyoutItem&gt;

    &lt;FlyoutItem Title=&quot;item1&quot;&gt;
        &lt;ShellContent ContentTemplate=&quot;{DataTemplate pages:ItemPage}&quot;/&gt;
    &lt;/FlyoutItem&gt;

    &lt;FlyoutItem Title=&quot;ABOUT&quot;&gt;
        &lt;ShellContent ContentTemplate=&quot;{DataTemplate pages:AboutPage}&quot;/&gt;
    &lt;/FlyoutItem&gt;

&lt;/Shell&gt;



At AppShell.xaml.cs

public AppShell()
{
    InitializeComponent();
    
    //goto login if you want
    Navigation.PushAsync(new LoginPage());
}

At LoginPage.xaml.cs

public StartPage()
{
	InitializeComponent();
    
    //hide bottom tabs
    Shell.SetTabBarIsVisible(this, false);
}

At LoginPage.xaml hide the top navigation:

&lt;ContentPage Shell.NavBarIsVisible=&quot;false&quot;&gt;

&lt;/ContentPage&gt;

The final step is to navigate back to the Shell tab page, the best place would be at the ViewModel of your LoginPage, you have to complete the login process and go to your main screen.

Task.Run(async () =&gt;
{
  //go to our main shell page with tabs and flyout menu
  await Shell.Current.Navigation.PopToRootAsync();
});

Hope that helps.

huangapple
  • 本文由 发表于 2023年2月7日 04:21:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/75366176.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定