按下后退按钮时如何在Windows Phone 8中转到上一页 [英] How to go to previous page in windows phone 8 when back button is pressed

查看:30
本文介绍了按下后退按钮时如何在Windows Phone 8中转到上一页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在基于 windows phone c# 的应用程序中有一个主页或登录页面,用户可以在其中输入登录详细信息,并在成功登录后将用户重定向到 page2.在这里,用户将看到一个包含几个项目的列表框.从此列表框中选择一个项目后,将打开一个名为Threadx"的新页面.(其中 x 是单击列表框中的 x 项目后打开的每个页面)

I have a home page or landing page in my windows phone c# based app where user enters login details and upon successful login user is redirected to page2 . Here the user will see a list box with few items . Upon selecting an item from this list box a new page called "Threadx" opens.(where x is the each page that opens upon clicking the x item in the list box)

当用户在此线程页面Threadx"上时,他可能会收到 Toast 通知,并且线程会根据该线程上的新回复或答案进行更新.

While user is on this Thread page "Threadx" he may receive the toast notifications and the thread gets updated with new replies or answers on that thread.

但是当用户点击后退按钮时,ThreadX"页面不会关闭,而是会进入之前的状态,消息数量较少,依此类推,直到应用程序关闭.

But When user clicks on back button the "ThreadX" page doesn't get closed and instead it goes to its previous state where it has less number of messages , and so on until the app gets closed.

protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        base.OnNavigatedTo(e);
        if (e.NavigationMode == NavigationMode.Back)
        {
            return;
        }
    }

我想知道这个Threadx"页面是否可以在点击后退按钮时关闭而不影响其他Threadx+1"、Threadx+2"...Threadx+n"页面.

I would like to know if this "Threadx" page can be closed upon clicking back button without affecting other "Threadx+1","Threadx+2"..."Threadx+n" pages.

任何帮助将不胜感激.

推荐答案

通常,当您离开一个页面并导航到另一个页面时,Windows 会将页面保留在其堆栈中.如果您想在按下后退按钮时导航到上一页,您可以执行以下操作:

Normally windows keeps the pages on it's stack when you leave a page and navigate to another page. If you want to navigate to the previous page on pressing the Back Button you can do following things:

OnNavigatedTo 方法添加以下行:

Add following line to OnNavigatedTo method:

Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_BackPressed;

HardwareButtons_BackPressed 方法添加定义:

    private void HardwareButtons_BackPressed(object sender, BackPressedEventArgs e)
    {
        e.Handled = true;
        if (Frame.CanGoBack)
            Frame.GoBack();
    }

不要忘记将 Windows.Phone.UI.Input 添加到命名空间列表中.

Don't forget to add Windows.Phone.UI.Input to the namespace list.

这篇关于按下后退按钮时如何在Windows Phone 8中转到上一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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