Files
MayShow/src/ViewModels/MainWindowViewModel.cs
T
2026-02-18 09:36:17 +09:00

51 lines
1.3 KiB
C#

using MayShow.Helpers;
using MayShow.Interfaces;
using System;
using System.Collections.Generic;
using System.Text;
namespace MayShow.ViewModels
{
class MainWindowViewModel : ChangeNotifier, IChangeViewModel
{
BaseViewModel _currentViewModel;
Stack<BaseViewModel> _viewModels;
public MainWindowViewModel(ITopLevelGrabber topLevelGrabber)
{
_viewModels = new Stack<BaseViewModel>();
var initialViewModel = new MainViewModel(this)
{
TopLevelGrabber = topLevelGrabber
};
_viewModels.Push(initialViewModel);
_currentViewModel = initialViewModel;
}
public BaseViewModel CurrentViewModel
{
get { return _currentViewModel; }
set { _currentViewModel = value; NotifyPropertyChanged(); }
}
#region IChangeViewModel
public void PushViewModel(BaseViewModel model)
{
_viewModels.Push(model);
CurrentViewModel = model;
}
public void PopViewModel()
{
if (_viewModels.Count > 1)
{
_viewModels.Pop();
CurrentViewModel = _viewModels.Peek();
}
}
#endregion
}
}