【问题标题】:Xamarin Forms Shell - Burger Menu with Pages with complex constructorsXamarin Forms Shell - 带有复杂构造函数的页面的汉堡菜单
【发布时间】:2019-12-06 07:09:07
【问题描述】:

我想使用 Xamarin.Forms Shell 创建带有汉堡菜单的页面。该菜单将包含页面:HomePage(带有 compex 构造函数)和 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)中执行此操作。感谢您的宝贵时间。

【问题讨论】:

    标签: c# .net xaml xamarin xamarin.forms


    【解决方案1】:

    你可以像下面的代码一样在汉堡菜单中添加弹出项目

    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);
        }
    
    }
    

    这里正在运行 GIF。

    【讨论】:

    猜你喜欢
    • 2019-04-19
    • 1970-01-01
    • 1970-01-01
    • 2018-08-16
    • 1970-01-01
    • 2018-11-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多