Xamarin Forms Shell - 带有带有复杂构造函数的页面的汉堡菜单

我想使用 Xamarin.Forms Shell 创建带有汉堡菜单的页面。该菜单将包含页面:HomePage(带有复杂构造函数)和AboutPage(带有默认构造函数)。AboutPage 没有问题,因为它可以在 xaml 中轻松创建,但我不知道如何使用 HomePage 添加新的 ShellItem


我尝试从 xaml.cs 创建此菜单项,但没有呈现。


AppShell.xaml.cs:


 public AppShell(IDataProvider dataProvider)

        {

            InitializeComponent();

            this.Items.Add(new ShellItem()

            {

                Title = "Home", Items = { new ShellSection()

                {

                    CurrentItem = new ShellContent()

                    {

                        Content = new HomePage(dataProvider)

                    }

                }}

            });

        }

那么如何使用 Xamarin Forms Shell 将页面与复杂构造器一起使用?如果可能的话,我什至更愿意从代码隐藏(xaml.cs)中执行此操作。感谢您的时间。


侃侃尔雅
浏览 125回答 1
1回答

qq_花开花谢_0

您可以在带有页面的汉堡菜单中添加弹出项目,如下代码所示public partial class AppShell : Xamarin.Forms.Shell{    public AppShell()    {        InitializeComponent();        ShellSection shell_section = new ShellSection        {            Title = "home",        };        shell_section.Items.Add(new ShellContent() { Content = new HomePage() });        ShellSection shell_section1 = new ShellSection        {            Title = "about",        };        shell_section1.Items.Add(new ShellContent() { Content = new AboutPage() });        myshell.Items.Add(shell_section);        myshell.Items.Add(shell_section1);    }}
打开App,查看更多内容
随时随地看视频慕课网APP