修改了Dialog的调用方式,和实现了添加设备添加到侧边菜单中

This commit is contained in:
2025-06-26 19:36:27 +08:00
parent 0391e76931
commit 244b67391d
11 changed files with 134 additions and 54 deletions

View File

@@ -1,8 +1,10 @@
using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
using PMSWPF.Data.Entities;
using PMSWPF.Data.Repositories;
using PMSWPF.Message;
using PMSWPF.Models;
using PMSWPF.Services;
@@ -16,20 +18,34 @@ public partial class MainViewModel : ViewModelBase
[ObservableProperty]
private ObservableCollection<MenuBean> _menus;
private readonly MenuRepository _menuRepository;
public MainViewModel(NavgatorServices navgatorServices)
{
_navgatorServices = navgatorServices;
_menuRepository = new MenuRepository();
_navgatorServices.OnViewModelChanged += () => { CurrentViewModel = _navgatorServices.CurrentViewModel; };
CurrentViewModel = new HomeViewModel();
CurrentViewModel.OnLoaded();
WeakReferenceMessenger.Default.Register<UpdateMenuMessage>( this,UpdateMenu);
}
private async void UpdateMenu(object recipient, UpdateMenuMessage message)
{
await LoadMenu();
}
public override async void OnLoaded()
{
MenuRepositories mr = new MenuRepositories();
var menuList= await mr.GetMenu();
Menus=new ObservableCollection<MenuBean>(menuList);
{
await LoadMenu();
}
private async Task LoadMenu()
{
var menuList= await _menuRepository.GetMenu();
Menus=new ObservableCollection<MenuBean>(menuList);
}
}