using System.Windows.Controls;
using XFEToolBox.Views.Windows;
namespace XFEToolBox.Utilities;
///
/// 导航中心
///
public static class NavigationCenter
{
///
/// 导航堆栈
///
public static List NavigationStack { get; set; } = [];
private static bool canGoBack;
///
/// 是否可以返回
///
public static bool CanGoBack
{
get { return canGoBack; }
set
{
if (MainWindow.Current is null)
return;
canGoBack = value;
MainWindow.Current.backTabBorder.Visibility = canGoBack ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed;
}
}
private static bool CheckCanGoBack() => NavigationStack.Count > 0 ? CanGoBack = true : CanGoBack = false;
///
/// 返回上一个导航堆栈
///
/// 是否从导航堆栈中移除
/// 是否成功
public static bool GoBack(bool removeStack = true)
{
if (MainWindow.Current is null)
return false;
MainWindow.Current.contentFrame.Content = NavigationStack[^2];
if (removeStack && NavigationStack.Count > 0)
NavigationStack.RemoveAt(NavigationStack.Count - 1);
CheckCanGoBack();
return true;
}
///
/// 导航至目标堆栈
///
/// 目标导航页面
/// 是否添加至导航堆栈中
/// 是否成功
public static bool Navigate(this Page page, bool addIntoStack = true)
{
if (MainWindow.Current is null)
return false;
MainWindow.Current.contentFrame.Content = NavigationStack[^1];
if (addIntoStack)
NavigationStack.Add(page);
CheckCanGoBack();
return true;
}
}