Files
ADP/MainModule/ViewModels/MainViewModel.cs
2026-06-05 10:57:09 +08:00

67 lines
2.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using UIShare.PubEvent;
using MainModule.ViewModels;
using UIShare.ViewModelBase;
namespace MainModule.ViewModels
{
public class MainViewModel : NavigateViewModelBase, IRegionMemberLifetime
{
#region
private bool IsInitialized = false;
private string _expandedCellName = string.Empty;
#endregion
#region
public bool KeepAlive => true; // 保持存活
public string ExpandedCellName
{
get => _expandedCellName;
set => SetProperty(ref _expandedCellName, value);
}
#endregion
#region
public ICommand LoadedCommand { get; set; }
#endregion
public MainViewModel(IContainerProvider containerProvider) : base(containerProvider)
{
LoadedCommand = new DelegateCommand(OnLoaded);
_eventAggregator.GetEvent<ExpandViewEvent>().Subscribe(OnCellExpandRequested);
}
#region
private void OnLoaded()
{
if (IsInitialized) return;
for (int i = 1; i <= 9; i++)
{
var parameters = new NavigationParameters { { "Name", $"TestCell{i}" } };
_regionManager.RequestNavigate($"TestCell{i}", "ProtocolStartView", parameters);
}
IsInitialized = true;
}
// 不再物理搬迁视图,只需修改一个字符串属性 ExpandedCellName
// XAML 里每个单元的 Style.Triggers 会根据该值处理隐藏 / 跨越 3x3。
private void OnCellExpandRequested(string cellName)
{
ExpandedCellName = cellName ?? string.Empty;
}
#endregion
#region
public override bool IsNavigationTarget(NavigationContext navigationContext)
{
// 之前帮你改好的单例复用逻辑(防止重复 new 和初始化视图)
return true;
}
#endregion
}
}