我正在尝试使用 C# 和 Xamarin.Forms 构建跨平台应用程序。它包含一个以MasterDetailPage. 在 Android 上,左上角有一个带有应用程序图标的按钮,用于切换滑出页面,而在 iOS 上没有这样的导航栏项目。
我将其分解为以下从 Xamarin 解决方案模板“Blank App (Xamarin.Forms Shared)”派生的最小示例,并替换了App-class 的实现:
public class App
{
    static MasterDetailPage MDPage;
    public static Page GetMainPage()
    {
        return new NavigationPage(
            MDPage = new MasterDetailPage {
                Master = new ContentPage {
                    Title = "Master",
                    Content = new StackLayout {
                        Children = { Link("A"), Link("B"), Link("C") }
                    },
                },
                Detail = new ContentPage { Content = new Label { Text = "A" } },
            });
    }
    static Button Link(string name)
    {
        var button = new Button { Text = name };
        button.Clicked += delegate {
            MDPage.Detail = new ContentPage { Content = new Label { Text = name } };
            MDPage.IsPresented = false;
        };
        return button;
    }
}
可以在GitHub 上找到解决方案以及生成的屏幕截图。
我的想法是在特定于 iOS 的代码中添加这样的“菜单”或“后退”按钮来修改类window.RootViewController.NavigationController.NavigationBar中的AppDelegate。但是window.RootViewController.NavigationController是null。
GetMainPage()替换by的返回类型NavigationPage而不是Page没有帮助。
我可以通过添加工具栏项MDPage.ToolbarItems.Add(...),但它们出现在右上角。