【发布时间】:2014-09-02 05:16:19
【问题描述】:
我正在尝试使用 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 特定代码中添加这样一个“菜单”或“后退”按钮,修改 AppDelegate 类中的 window.RootViewController.NavigationController.NavigationBar。但是window.RootViewController.NavigationController 是null。
将GetMainPage() 的返回类型替换为NavigationPage 而不是Page 没有帮助。
我可以通过MDPage.ToolbarItems.Add(...) 添加工具栏项,但它们出现在右上角。
【问题讨论】:
标签: ios xamarin xamarin.forms navigationbar master-detail