在Windows Phone 8的实现类Tab导航模式 - 如何? [英] Implementing Tab-like Navigation model in Windows Phone 8 — How?

查看:131
本文介绍了在Windows Phone 8的实现类Tab导航模式 - 如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在试图实现一个非常类似于在Windows Phone Internet Explorer的应用程序8.



的IE应用程序可以有多个选项卡的导航方案用户可以切换。每个选项卡都具有其自己的历史。打在手机上的后退按钮需要你在标签上的导航历史记录的前一页(不是 PhoneApplicationFrame.BackStack 。如果没有前几页,后退按钮带你到前面打开的标签页,或者,如果没有,退出应用程序。



为什么这是困扰我




  • Application.RootVisual 只能设置一次。所以,你不能有两个PhoneApplicationFrames,每一个都有自己BackStack,以 RootVisual 两者之间进行切换。


  • 您无法遍历BackStack(这是一个堆栈,毕竟)。只能叫 GoBack的()。调用 GoForward()会抛出异常。


  • PhoneApplicationFrame.GoBack( )从中只能通过 PhoneApplicationFrame.Navigate(...)法再次加BackStack删除条目。因此,操纵BackStack是一个没有去。




高见




  • 请在词典<枚举列表与LT;串>> 这与每次调用自定义更新 NavigationService.Navigate(tabTypeEnum,uriString中,则params)。这将保持导航历史记录每个 tabType ,允许我们可能通过当前选项卡的历史导航的时候 BackKeyPress 事件被处理。 坏的事情是,要求导航(...)进入前几页(而不是 GoBack的)将添加到BackStack。因此,需要维护的,现在伤害了我的大脑


  • 创建自定义的 NavigationAwareTabPage:的PhoneApplicationPage ,这使跟踪自己的浏览历史和假货按当其内容更改动画过渡导航。唯一一次我们称之为真正 导航是,当我们切换从一个标签到另一个。 (我认为这是IE浏览器的应用程序做什么。)以及 BackKeyPress 将不得不像下面。




这:

 无效RootFrame_BackKeyPress(对象发件人,发送CancelEventArgs E)
{
VAR rootFrame =发件人为PhoneApplicationFrame;
如果(rootFrame.CanGoBack)
{
//获取NavigationAwarePage
VAR navAwarePage = rootFrame.Content为NavigationAwareTabPage;
如果(navAwarePage.CanGoBack())
{
//该方法向下到下一页
//通过改变navAwarePage.Content
navAwarePage。 GoBackToPreviousPage();
e.Cancel = TRUE;
}
}
}



有没有人沿着这条道路?


解决方案

的ReactiveUI如何覆盖后退按钮所有神奇的是在这里:



https://github.com/reactiveui /ReactiveUI/blob/master/ReactiveUI.Mobile/WP8AutoSuspendApplication.cs#L91



这是这部作品在ReactiveUI方式是,有一个名为内容控制 RoutedViewHost 正在听回被信号(你可以做任何你响应硬件后退按钮希望并取消默认操作)。 ReactiveUI维护自己的基于视图模型回堆栈和操纵的的的而不是使用WP8s,你永远不会调用WP8s导航方法。



这实际上意味着即,从WP8的角度来看,只有永远一个在整个申请页面。 WP8的真的希望创建页面本身,以及它在 WMAppManifest.xml 指定。



不要试图参与WP8的框架体系,它真的要工作,以自己的方式,你将无法说服,否则它。



最后一个重要的事情,如果你在底部的的回堆栈,您必须允许的默认返回动作发生(即什么WP8想做的事,带你出去的应用程序)。否则,你可能会失败,认证你就错了™。


I am currently trying to implement a navigation scheme that closely resembles that of the Internet Explorer app on Windows Phone 8.

The IE app can have multiple tabs that the user can switch between. Each of these tabs has its own history. Hitting the Back Button on the phone takes you to the previous page in that tab's Navigation history (Not the PhoneApplicationFrame.BackStack). If there are no previous pages, the back button takes you to the previous opened tab or, if none, exits the app.

Why this is troubling me

  • Application.RootVisual can only be set once. So you can't have two PhoneApplicationFrames, each with its own BackStack, to swap RootVisual between the two.

  • You cannot traverse the BackStack (it is a Stack, after all). Can only call GoBack(). Calling GoForward() will throw an Exception.

  • PhoneApplicationFrame.GoBack() removes entries from the BackStack which can only be added again through the PhoneApplicationFrame.Navigate(...) method. So, manipulating the BackStack is a no-go.

Bright Ideas

  • Keep a Dictionary<enum, List<string>> which is updated with each call to a custom NavigationService.Navigate(tabTypeEnum, uriString, params). This will keep the Navigation history for each tabType, allowing us to possibly Navigate through the current Tab's history when the BackKeyPress event is handled. Bad thing is, calling Navigate(...) to go to previous pages (instead of GoBack) will add to the BackStack. So requires maintenance that hurts my brain right now.

  • Create a custom NavigationAwareTabPage : PhoneApplicationPage, which keeps track of its own navigation history and fakes navigation by animating a transition when its Content is changed. The only time we call a true Navigate is when we switch from one tab to another. (I think this is what the IE app does.) And the BackKeyPress would have to look like below.

This:

void RootFrame_BackKeyPress(object sender, CancelEventArgs e)
{
    var rootFrame = sender as PhoneApplicationFrame;
    if (rootFrame.CanGoBack)
    {
        // Get the NavigationAwarePage
        var navAwarePage = rootFrame.Content as NavigationAwareTabPage;
        if(navAwarePage.CanGoBack())
        {
            // This method "navigates" to the next page
            // by changing the navAwarePage.Content
            navAwarePage.GoBackToPreviousPage();
            e.Cancel = true;
        }
    }
}

Has anyone been down this road?

解决方案

All the magic of how ReactiveUI overrides the Back button is here:

https://github.com/reactiveui/ReactiveUI/blob/master/ReactiveUI.Mobile/WP8AutoSuspendApplication.cs#L91

The way that this works in ReactiveUI is that there is a content control named RoutedViewHost that is listening to the Back being signaled (you can do whatever you want in response to the hardware Back button and cancel the default action). ReactiveUI maintains its own ViewModel-based back stack and manipulates that instead of using WP8s, and you never call WP8s navigation methods.

This effectively means that, from WP8's perspective, there is only ever one page in the entire application. WP8 really wants to create that page itself, and it's specified in WMAppManifest.xml.

Don't try to participate in WP8's Frame system, it really wants to work its own way and you won't be able to convince it otherwise.

One last important thing, if you're at the bottom of your back stack, you must allow the default Back action to happen (i.e. what WP8 wanted to do, take you out of the app). Otherwise you'll probably fail Certification and you're Doing It Wrong™.

这篇关于在Windows Phone 8的实现类Tab导航模式 - 如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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