简体   繁体   English

UWP 导航(Template10)、Pivo​​t 控件、多帧

[英]UWP navigation (Template10), Pivot control, multiple frames

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.我正在尝试在我的 UWP 应用程序中实现以下导航样式(使用 Template10),但正在努力如何将多个帧用作独立的历史堆栈。

并排

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);

but nav is always null.nav始终为空。

I've also tried:我也试过:

PageAFrame.Navigate(typeof(PageA));

But my ViewModels do not get instantiated.但是我的 ViewModel 没有被实例化。

Any ideas?有任何想法吗?

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.注意:我不使用汉堡包菜单的原因是我需要能够在枢轴之间交换,但仍保留每个枢轴的独立历史堆栈。

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 绝对支持的一个重要用例,但人们认识到单帧是开箱即用的,多帧需要开发人员代码。

Conceptually, T10 creates a NavigationService that wraps every frame.从概念上讲,T10 创建了一个包装每一帧的 NavigationService。 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.创建的第一个 NavService 会自动附加到应用程序后退按钮,但开发人员可以使用 NavigationServiceFactory 中的参数重新分配或关闭该按钮。

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

For every frame you introduce you need to create an associated NavigationService using the factory method.对于您引入的每一帧,您都需要使用工厂方法创建一个关联的 NavigationService。 Doing so will register it with T10 and make it work fine.这样做会将其注册到 T10 并使其正常工作。 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.请记住,始终使用 NavigationService.Navigate() 而不是 Frame.Navigate() 并按照您的指示使用 GetForFrame() 访问 NavigationService。

Make sense?有道理?

Template10 navigation service takes care of the root frame of the application, it doesn't know about your nested frames. Template10 导航服务负责应用程序的根框架,它不知道您的嵌套框架。 So my advice for you (and that is what I did) is to handle nested frame navigation manually and don't waste your time trying to find a way to do that in Template10.所以我给你的建议(这就是我所做的)是手动处理嵌套框架导航,不要浪费你的时间试图在 Template10 中找到一种方法来做到这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM