Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Uwp 在主页中如何停止向后导航?_Uwp - Fatal编程技术网

Uwp 在主页中如何停止向后导航?

Uwp 在主页中如何停止向后导航?,uwp,Uwp,我正在使用Windows Template Studio,现在遇到一个导航问题 假设我有一个主页,setingspage 首先,打开应用程序,它导航到主页,然后我点击导航到设置页面。然后单击主页导航到主页 Frame.CanGoBack && activeFrame.CurrentSourcePageType!=typeof(MainPage) 此时,goback按钮起作用。但是返回命令正在设置SPAGE-->主页 Frame.CanGoBack && acti

我正在使用Windows Template Studio,现在遇到一个导航问题

假设我有一个主页,setingspage

首先,打开应用程序,它导航到主页,然后我点击导航到设置页面。然后单击主页导航到主页

Frame.CanGoBack && activeFrame.CurrentSourcePageType!=typeof(MainPage)
此时,goback按钮起作用。但是返回命令正在设置SPAGE-->主页

Frame.CanGoBack && activeFrame.CurrentSourcePageType!=typeof(MainPage)
我希望在主页中禁用“返回”按钮

Frame.CanGoBack && activeFrame.CurrentSourcePageType!=typeof(MainPage)
这是WTS中的导航服务代码。在主页中如何停止向后导航?谢谢

using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media.Animation;

namespace WeRecognition.Services
{
    public static class NavigationService
    {
        private static Frame _frame;
        public static Frame Frame
        {
            get
            {
                if (_frame == null)
                {
                    _frame = Window.Current.Content as Frame;
                }

                return _frame;
            }
            set
            {
                _frame = value;
            }
        }

        public static bool CanGoBack => Frame.CanGoBack;
        public static bool CanGoForward => Frame.CanGoForward;

        public static void GoBack() => Frame.GoBack();
        public static void GoForward() => Frame.GoForward();

        public static bool Navigate(Type pageType, object parameter = null, NavigationTransitionInfo infoOverride = null)
        {
            // Don't open the same page multiple times
            if (Frame.Content?.GetType() != pageType)
            {
                return Frame.Navigate(pageType, parameter, infoOverride);
            }
            else
            {
                return false;
            }
        }

        public static bool Navigate<T>(object parameter = null, NavigationTransitionInfo infoOverride = null) where T : Page => Navigate(typeof(T), parameter, infoOverride);
    }
}
使用系统;
使用Windows.UI.Xaml;
使用Windows.UI.Xaml.Controls;
使用Windows.UI.Xaml.Media.Animation;
命名空间WeRecognition.Services
{
公共静态类导航服务
{
私有静态帧_帧;
公共静态框架
{
收到
{
如果(_frame==null)
{
_frame=Window.Current.Content作为frame;
}
返回帧;
}
设置
{
_帧=值;
}
}
公共静态bool CanGoBack=>Frame.CanGoBack;
公共静态bool CanGoForward=>Frame.CanGoForward;
公共静态void GoBack()=>Frame.GoBack();
公共静态void GoForward()=>Frame.GoForward();
公共静态bool-Navigate(类型pageType,对象参数=null,NavigationTransitionInfo-infoOverride=null)
{
//不要多次打开同一页
if(Frame.Content?.GetType()!=pageType)
{
返回帧。导航(页面类型、参数、信息覆盖);
}
其他的
{
返回false;
}
}
公共静态bool-Navigate(object参数=null,NavigationTransitionInfo-infoOverride=null),其中T:Page=>Navigate(typeof(T),参数,infoOverride);
}
}

您有两种解决方案:

  • 导航到主页面后,清除框架的后堆栈

    Frame.BackStack.Clear();
    
  • 如果当前页面是主页,则将此CanGoBack行更改为返回false

    Frame.CanGoBack && activeFrame.CurrentSourcePageType!=typeof(MainPage)
    
  • 注意:对于第二个选项,您没有清除back stack,而是隐藏/禁用了back按钮

    试一下,看看哪个对你更合适