【发布时间】:2017-01-15 05:38:13
【问题描述】:
我正在尝试在我的 Xamarin.Forms 应用程序中配置主从导航,而我的 UWP 目标在 Windows 10 上运行。
当我运行 Xamarin 提供的示例 Master-Detail 应用程序(遵循 https://developer.xamarin.com/guides/xamarin-forms/user-interface/navigation/master-detail-page/)并将 MasterBehavior 更改为 Popover 时,我看到以下行为:
启动:
选择汉堡图标:
进行选择:
在我的 prism 应用中,我导航到 MainPage/View1:
protected override void OnInitialized()
{
InitializeComponent();
var task = NavigationService.NavigateAsync("MainPage/View1");
...
}
MainPage 是我的 MasterDetailPage,MasterBehavior 设置为 Popover,View1 是 ContentPage。
主页:
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:views="clr-namespace:My.Mobile.Application.Views;assembly=My.Mobile.Application"
x:Class="My.Mobile.Application.Frame.MainPage"
MasterBehavior="Popover">
<MasterDetailPage.Master>
<views:MasterPage x:Name="masterPage" />
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<NavigationPage>
<x:Arguments>
<views:View1 />
</x:Arguments>
</NavigationPage>
</MasterDetailPage.Detail>
</MasterDetailPage>
视图1:
public View1()
{
NavigationPage.SetHasNavigationBar(this,false);
InitializeComponent();
}
在启动时,我没有看到任何导航栏,只有 View1 的内容(目前只是一个红屏):
如果我将 MainPage.xaml 的 MasterBehavior 更改为 Default 而不是 Popover,并删除 View1 中的 SetHasNavigationBar,我会在应用启动时看到侧边菜单:
主页:
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:views="clr-namespace:My.Mobile.Application.Views;assembly=My.Mobile.Application"
x:Class="My.Mobile.Application.Frame.MainPage"
MasterBehavior="Default">
<MasterDetailPage.Master>
<views:MasterPage x:Name="masterPage" />
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<NavigationPage>
<x:Arguments>
<views:View1 />
</x:Arguments>
</NavigationPage>
</MasterDetailPage.Detail>
</MasterDetailPage>
视图1:
public View1()
{
//NavigationPage.SetHasNavigationBar(this,false);
InitializeComponent();
}
当我在启动后将 MasterBehavior 设置为 Default 进行选择时,我现在看到了汉堡菜单。
我是否可以在我的解决方案中添加或验证任何内容,以模拟将 MasterBehavior 设置为 Popup 的 Xamarin 示例行为?
【问题讨论】:
标签: xamarin navigation xamarin.forms prism master-detail