我想使用 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)中執行此操作。感謝您的時間。
1 回答

qq_花開花謝_0
TA貢獻1835條經驗 獲得超7個贊
您可以在帶有頁面的漢堡菜單中添加彈出項目,如下代碼所示
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);
? ? }
}
- 1 回答
- 0 關注
- 146 瀏覽
添加回答
舉報
0/150
提交
取消