UWP导航(Template10),数据透视控件,多个框架 [英] UWP navigation (Template10), Pivot control, multiple frames

查看:129
本文介绍了UWP导航(Template10),数据透视控件,多个框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的UWP应用(使用Template10)中实现以下导航样式,但是正在努力将多个框架用作独立的历史堆栈.

I'm trying to implement the following style of navigation in my UWP app (using Template10) but am struggling how to use the multiple frames as independent history stacks.

在枢轴的每个框架中,我希望有一个独立的框架,该框架具有自己的历史记录和后退堆栈.在框架之间导航只能通过枢轴进行.

Within each frame of the pivot, I'd want to have an independent frame that has it's own history and back stack. Navigating between the frames would only be possible via the pivot.

我正在考虑使用类似于以下代码:

I was thinking of using code similar to the below:

<Pivot>
   <PivotItem Header="PageA">
      <Frame x:Name="PageAFrame" />
   </PivotItem>
   <PivotItem Header="PageB">
      <Frame x:Name="PageBFrame" />
   </PivotItem>
   <PivotItem Header="PageC">
      <Frame x:Name="PageCFrame" />
   </PivotItem>
</Pivot>

但是,我不确定如何实际实现导航.我尝试使用类似于下面的代码,但是没有运气:

However, I'm not sure how to actually implement the navigation. I've tried using code similar to the below, but with no luck:

var nav = Template10.Services.NavigationService.NavigationService.GetForFrame(PageAFrame);

nav始终为空.

我也尝试过:

PageAFrame.Navigate(typeof(PageA));

但是我的ViewModels没有被实例化.

But my ViewModels do not get instantiated.

有什么想法吗?

注意:之所以不使用汉堡菜单,是因为我需要能够在枢轴之间进行交换,但仍保留每个枢轴的独立历史记录.

Note: the reason why I'm not using a hamburger menu is because I need to be able to swap between the pivots but still preserve the independent history stack of each.

推荐答案

嵌套帧很好. T10绝对支持多个框架,这是一个重要的用例,但是人们意识到开箱即用地支持单个框架,而多个框架则需要开发人员代码.

Nested frames are fine. Multiple frames are an important use case that are definitely supported by T10, but people recognize that a single frame is supported out of the box and multiple frames requires developer code.

从概念上讲,T10创建一个包装每帧的NavigationService.创建的第一个NavService将自动附加到应用程序后退按钮,但是开发人员可以使用NavigationServiceFactory中的参数来重新分配或关闭它.

Conceptually, T10 creates a NavigationService that wraps every frame. The first NavService created is automatically attached to the app back button but this can be reassigned or turned off by the developer using arguments in the NavigationServiceFactory.

https://github.com/Windows-XAML/Template10/blob/master/Template10%20(Library)/Common/Bootstrapper/BootStrapper.cs#L278

对于您介绍的每个框架,都需要使用工厂方法创建关联的NavigationService.这样做会将其注册到T10并使其正常工作.话虽如此,您的应用程序中的工作流程现在由您决定.请记住,始终使用NavigationService.Navigate()而不是Frame.Navigate()并使用GetForFrame()来访问NavigationService,就像您指出的那样.

For every frame you introduce you need to create an associated NavigationService using the factory method. Doing so will register it with T10 and make it work fine. That being said, the workflow in your app is now up to you. Remember, instead of Frame.Navigate() always use NavigationService.Navigate() and access the NavigationService with GetForFrame() just like you indicated.

有道理吗?

这篇关于UWP导航(Template10),数据透视控件,多个框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆