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