90 lines
2.8 KiB
C#
90 lines
2.8 KiB
C#
using Prism.Mvvm;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using UIShare.UIViewModel;
|
|
|
|
namespace UIShare.GlobalVariable
|
|
{
|
|
/// <summary>
|
|
/// 单个 Tab(主程序 / 错误程序)的子程序导航状态。
|
|
/// 主程序和错误程序各自持有一个独立实例,互不干扰。
|
|
/// </summary>
|
|
public class ProgramNavigationState : BindableBase
|
|
{
|
|
/// <summary>是否为错误程序 Tab</summary>
|
|
public bool IsErrorTab { get; set; }
|
|
|
|
public Stack<ProgramVM> NavigationStack { get; } = new();
|
|
|
|
private ProgramVM _currentProgram;
|
|
public ProgramVM CurrentProgram
|
|
{
|
|
get => _currentProgram;
|
|
set
|
|
{
|
|
if (SetProperty(ref _currentProgram, value))
|
|
RaisePropertyChanged(nameof(DisplaySteps));
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// DataGrid 实际绑定的步骤集合。
|
|
/// 根程序 + 错误 Tab → ErrorStepCollection;其他情况 → StepCollection。
|
|
/// </summary>
|
|
public ObservableCollection<StepVM> DisplaySteps
|
|
{
|
|
get
|
|
{
|
|
if (CurrentProgram == null)
|
|
return new ObservableCollection<StepVM>();
|
|
// 在根程序且是错误 Tab → 显示错误步骤集合
|
|
if (NavigationStack.Count == 0 && IsErrorTab)
|
|
return CurrentProgram.ErrorStepCollection;
|
|
// 其他情况(主 Tab 或已进入子程序)→ 显示正常步骤集合
|
|
return CurrentProgram.StepCollection;
|
|
}
|
|
}
|
|
|
|
private string _breadcrumbPath = "主程序";
|
|
public string BreadcrumbPath
|
|
{
|
|
get => _breadcrumbPath;
|
|
set => SetProperty(ref _breadcrumbPath, value);
|
|
}
|
|
|
|
private bool _canGoBack;
|
|
public bool CanGoBack
|
|
{
|
|
get => _canGoBack;
|
|
set => SetProperty(ref _canGoBack, value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 用根程序初始化导航状态
|
|
/// </summary>
|
|
public void Initialize(ProgramVM rootProgram, string label)
|
|
{
|
|
NavigationStack.Clear();
|
|
CurrentProgram = rootProgram;
|
|
BreadcrumbPath = label;
|
|
CanGoBack = false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 清空导航栈,回到根程序
|
|
/// </summary>
|
|
public void Reset(ProgramVM rootProgram, string label)
|
|
{
|
|
NavigationStack.Clear();
|
|
CurrentProgram = rootProgram;
|
|
BreadcrumbPath = label;
|
|
CanGoBack = false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据栈状态刷新 CanGoBack
|
|
/// </summary>
|
|
public void UpdateCanGoBack() => CanGoBack = NavigationStack.Count > 0;
|
|
}
|
|
}
|