2025-05-29 08:58:58 +08:00
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
|
|
|
using CommunityToolkit.Mvvm.Messaging;
|
2025-05-29 21:46:53 +08:00
|
|
|
|
using PMSWPF.Data.Entities;
|
2025-05-29 08:58:58 +08:00
|
|
|
|
using PMSWPF.Message;
|
2025-05-29 21:46:53 +08:00
|
|
|
|
using System.Collections.ObjectModel;
|
2025-06-10 20:55:39 +08:00
|
|
|
|
using PMSWPF.Services;
|
2025-05-29 08:58:58 +08:00
|
|
|
|
|
|
|
|
|
|
namespace PMSWPF.ViewModels
|
|
|
|
|
|
{
|
|
|
|
|
|
partial class MainViewModel : ObservableRecipient, IRecipient<MyMessage>
|
|
|
|
|
|
{
|
2025-06-10 20:55:39 +08:00
|
|
|
|
private readonly NavgatorServices _navgatorServices;
|
|
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
|
private ViewModelBase currentViewModel;
|
|
|
|
|
|
public MainViewModel(NavgatorServices navgatorServices)
|
|
|
|
|
|
{
|
|
|
|
|
|
_navgatorServices = navgatorServices;
|
|
|
|
|
|
_navgatorServices.OnViewModelChanged += () =>
|
|
|
|
|
|
{
|
|
|
|
|
|
CurrentViewModel = _navgatorServices.CurrentViewModel;
|
|
|
|
|
|
};
|
2025-05-29 08:58:58 +08:00
|
|
|
|
IsActive = true;
|
2025-06-10 20:55:39 +08:00
|
|
|
|
CurrentViewModel = new HomeViewModel();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void NavgateTo<T>() where T : ViewModelBase
|
|
|
|
|
|
{
|
|
|
|
|
|
_navgatorServices.NavigateTo<T>();
|
2025-05-29 08:58:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string text = "Hello Count:";
|
|
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
|
string message;
|
|
|
|
|
|
|
|
|
|
|
|
public void Receive(MyMessage message)
|
|
|
|
|
|
{
|
|
|
|
|
|
Message = text + message.Count;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|