Xamarin形成母版详细信息将母版保留在左侧 [英] Xamarin Forms Master Detail Keep Master on the left
问题描述
我试图始终将主页"(菜单)保持在我的MasterDetailPage"的左侧,我不希望导航使用户离开MasterDetailPage并使用户按下后退"按钮来返回.
I am trying to keep the Master page (menu) to the left of My MasterDetailPage at all times, I do not want the navigation to take the user away from the MasterDetailPage and make the user press a back button to get back.
我正在看左侧的传统汉堡栏菜单,只需更改详细信息"页面并将主菜单保持在原位即可.
I am looking a traditional burger bar menu to the left that simply changes the Detail page and keeps the master in place.
我现在所拥有的:
public partial class App : Application
{
public static NavigationPage NavPage { get; private set; }
private static RootPage RootPage;
public static bool MenuIsPresented
{
get
{
return RootPage.IsPresented;
}
set
{
RootPage.IsPresented = value;
}
}
public App()
{
InitializeComponent();
MenuPage menuPage = new MenuPage();
NavPage = new NavigationPage(new FirstPage());
RootPage = new RootPage();
RootPage.Master = menuPage;
RootPage.Detail = NavPage;
MainPage = RootPage;
}
...
}
还有我的ViewModel命令
And my ViewModel Command
async void GoSecondPageAsync(object obj)
{
await App.NavPage.PushAsync(new SecondPage());
App.MenuIsPresented = false;
}
但这只是在堆栈顶部创建一个新页面,并带有一个返回到MasterDetailPage的后退按钮,而我所希望的只是停留在MasterDetailPage中.
But this just creates a new page on top of the stack with a back button back to the MasterDetailPage, while all I want is to stay within the MasterDetailPage.
推荐答案
您可以推送新页面,而只需从NavigationStack
中删除第一个页面即可.例如:
You can push the new page and just remove the first one from the NavigationStack
For example:
async void GoSecondPageAsync(object obj)
{
await App.NavPage.PushAsync(new SecondPage());
var removePage = App.NavPage.Navigation.NavigationStack[0];
App.NavPage.Navigation.RemovePage(removePage);
App.MenuIsPresented = false;
}
尽管,如果您始终只想替换页面,您是否真的甚至需要NavigationPage,也不能只设置RootPage.Detail=new SecondPage();
Although, if you just always want to replace the page do you really even need the NavigationPage and can't you just set the RootPage.Detail=new SecondPage();
这篇关于Xamarin形成母版详细信息将母版保留在左侧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!