Xamarin.forms 导航页面上缺少后退按钮

Xamarin.forms 导航页面上缺少后退按钮,xamarin.forms,prism,Xamarin.forms,Prism,我正在Xamarin.Forms 2.3.4.247项目中使用Prism.Forms 6.3。当我在主/详细设置中导航到详细信息页面时,我很难跟踪为什么返回箭头按钮不可见 我可以很好地导航到页面,但“后退”按钮从未出现。相反,汉堡菜单图标始终可见。这是我的“主页” 在应用程序启动期间,我已经这样设置了我的导航页面,因此我首先进入提要页面,然后我可以导航到选项页面 public class App : PrismApplication { public App(IPlatformIniti

我正在Xamarin.Forms 2.3.4.247项目中使用Prism.Forms 6.3。当我在主/详细设置中导航到详细信息页面时,我很难跟踪为什么返回箭头按钮不可见

我可以很好地导航到页面,但“后退”按钮从未出现。相反,汉堡菜单图标始终可见。这是我的“主页”

在应用程序启动期间,我已经这样设置了我的
导航页面
,因此我首先进入
提要页面
,然后我可以导航到
选项页面

public class App : PrismApplication
{
    public App(IPlatformInitializer dependencyRegister) : base(dependencyRegister) { }

    protected override void OnInitialized()
    {
        base.NavigationService.NavigateAsync("MainPage/NavigationPage");
    }

    protected override void RegisterTypes()
    {
        var builder = new ContainerBuilder();
        builder.RegisterModule<NavigationRegistration>();
        builder.RegisterModule<ServicesRegistration>();
        base.Container.RegisterTypeForNavigation<NavigationPage>();
        // This is deprecated but we have to wait for Prism.Autofac to update itself
        builder.Update(base.Container);
    }
}
公共类应用程序:PrismApplication
{
公共应用程序(IPlatformInitializer dependencyRegister):基(dependencyRegister){}
受保护的覆盖无效OnInitialized()
{
base.NavigationService.NavigateAsync(“主页/导航页”);
}
受保护的覆盖无效注册表类型()
{
var builder=new ContainerBuilder();
builder.RegisterModule();
builder.RegisterModule();
base.Container.RegisterTypeForNavigation();
//这已被弃用,但我们必须等待Prism.Autofac进行自我更新
builder.Update(base.Container);
}
}
与导航相关的DI注册在此模块中完成:

internal class NavigationRegistration : Module
{
    /// <summary>
    /// Load the navigation related types into the given builder.
    /// </summary>
    /// <param name="builder">Container Builder that will be turned into the final IOC Container</param>
    protected override void Load(ContainerBuilder builder)
    {
        // Register the NavigationPage in Xamarin with the Prism Navigation system.
        //builder.RegisterType<NavigationPage>().AsSelf();
        //PageNavigationRegistry.Register(nameof(NavigationPage), typeof(NavigationPage));

        // Get all of the Types that represent a View in our assembly for DI and navigation registration
        // If start-up time ever becomes an issue, we can replace this assembly scan with explicit registrations.
        Type[] viewTypes = base.ThisAssembly.GetTypes().Where(type => type.IsAssignableTo<Page>()).ToArray();

        // Iterate over each discovered View Type and register it with the navigation system and DI container.
        for(int index = 0; index < viewTypes.Length; index++)
        {
            Type viewType = viewTypes[index];
            builder.RegisterType(viewType).Named<Page>(viewType.Name);

            // If we ever need to disconnect a view name from its Type name, we can do so here.
            // We would build a custom attribute to decorate the view with, pull the attribute from the Type
            // and register the Type with the attribute value.
            PageNavigationRegistry.Register(viewType.Name, viewType);
        }
    }
}
内部类导航注册:模块
{
/// 
///将导航相关类型加载到给定的生成器中。
/// 
///将转换为最终IOC容器的容器生成器
受保护的覆盖无效负载(ContainerBuilder builder)
{
//在Prism导航系统中注册Xamarin中的NavigationPage。
//builder.RegisterType().AsSelf();
//Register(nameof(NavigationPage),typeof(NavigationPage));
//获取程序集中表示视图的所有类型,以进行DI和导航注册
//如果启动时间成为一个问题,我们可以用显式注册替换此程序集扫描。
类型[]viewTypes=base.ThisAssembly.GetTypes().Where(类型=>Type.IsAssignableTo()).ToArray();
//迭代每个发现的视图类型,并将其注册到导航系统和DI容器中。
for(int index=0;index

同样,我可以毫无问题地查看我的每个详细信息页面,汉堡包菜单存在,我可以打开母版页查看用于导航的按钮。一旦我到了那里,我就不能向后导航了。这是我自己应该做的吗?

你需要用MainPage=new NavigationPage(new StartPage())启动你的应用程序;这就是正常情况下的解决方法。所以,也许可以尝试注册包装在NavigationPage中的主页

要在uri中使用
NavigationPage
,您应该在
App.xaml.cs
中注册它以进行导航:

protected override void RegisterTypes()
{
    // your registrations
    Container.RegisterTypeForNavigation<NavigationPage>();
}
受保护的覆盖无效注册表类型()
{
//您的注册
Container.RegisterTypeForNavigation();
}

我不确定我是否正确理解了你的问题,但听起来这是正常的行为。在我使用XF/Prism的(简短)经验中,从主控器开始的每个导航都是堆栈的开始。如果您要添加另一个页面,例如从母版->页面A->页面B,我希望页面A有汉堡包菜单,但转到页面B会给您返回箭头。

导航到母版页
“/MasterPage/NavigationPage/ViewA”

使用“后退”按钮从ViewA导航出母版页
“ViewB”

这不是Prism的工作方式,Prism处理任务,您只需导航到您的页面即可。我没有想到要将该代码粘贴到我的OP中;我已经注册了你已经显示的类型。然后更新你的问题。这是很重要的一部分。还有,看看这个,我会的。我认为我显示的导航URI是
NavigationPage/FeedPage
,并说在那里导航已经足够了。如果我的DI没有设置,它将不起作用:)这对你来说是显而易见的,因为你现在正在处理它。而且,我不确定它是否会起作用。我假设Prism只使用模式导航,没有注册
NavigationPage
。请张贴你的整个注册方法,这可能会有帮助。我不确定我读对了你的问题,但听起来这是正常的行为。在我使用XF/Prism的(简短)经验中,从主控器开始的每个导航都是堆栈的开始。如果您要添加另一个页面,例如从Master->PageA->PageB,我希望A页有汉堡包菜单,但转到PageB会给您返回箭头。谢谢!这正是我的问题所在。我最初导航到
MainPage/NavigationPage/FeedPage
,想转到一个名为Foo的子视图。我以
导航页面/FooPage
的身份导航。将其更改为
NavigationPage/FeedPage/FooPage
修复了它。当我在
FooPage
woot上着陆时,我有了后退按钮!耶!我会加上它作为答案。:)
public class App : PrismApplication
{
    public App(IPlatformInitializer dependencyRegister) : base(dependencyRegister) { }

    protected override void OnInitialized()
    {
        base.NavigationService.NavigateAsync("MainPage/NavigationPage");
    }

    protected override void RegisterTypes()
    {
        var builder = new ContainerBuilder();
        builder.RegisterModule<NavigationRegistration>();
        builder.RegisterModule<ServicesRegistration>();
        base.Container.RegisterTypeForNavigation<NavigationPage>();
        // This is deprecated but we have to wait for Prism.Autofac to update itself
        builder.Update(base.Container);
    }
}
internal class NavigationRegistration : Module
{
    /// <summary>
    /// Load the navigation related types into the given builder.
    /// </summary>
    /// <param name="builder">Container Builder that will be turned into the final IOC Container</param>
    protected override void Load(ContainerBuilder builder)
    {
        // Register the NavigationPage in Xamarin with the Prism Navigation system.
        //builder.RegisterType<NavigationPage>().AsSelf();
        //PageNavigationRegistry.Register(nameof(NavigationPage), typeof(NavigationPage));

        // Get all of the Types that represent a View in our assembly for DI and navigation registration
        // If start-up time ever becomes an issue, we can replace this assembly scan with explicit registrations.
        Type[] viewTypes = base.ThisAssembly.GetTypes().Where(type => type.IsAssignableTo<Page>()).ToArray();

        // Iterate over each discovered View Type and register it with the navigation system and DI container.
        for(int index = 0; index < viewTypes.Length; index++)
        {
            Type viewType = viewTypes[index];
            builder.RegisterType(viewType).Named<Page>(viewType.Name);

            // If we ever need to disconnect a view name from its Type name, we can do so here.
            // We would build a custom attribute to decorate the view with, pull the attribute from the Type
            // and register the Type with the attribute value.
            PageNavigationRegistry.Register(viewType.Name, viewType);
        }
    }
}
protected override void RegisterTypes()
{
    // your registrations
    Container.RegisterTypeForNavigation<NavigationPage>();
}