实现导航跳转

This commit is contained in:
2025-07-30 12:09:00 +08:00
parent 3b5ecef895
commit 1ebc1a4df6
21 changed files with 150 additions and 248 deletions

View File

@@ -7,6 +7,7 @@ using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows;
using DMS.ViewModels;
using DMS.WPF.ViewModels.Items;
using DMS.WPF.Views;
namespace DMS.WPF.Services;
@@ -29,19 +30,19 @@ public class NavigationService : INavigationService
/// <summary>
/// 导航到指定键的视图,并传递参数。
/// </summary>
public async Task NavigateToAsync(string viewKey, object parameter = null)
public async Task NavigateToAsync(MenuItemViewModel menu)
{
if (string.IsNullOrEmpty(viewKey))
if (string.IsNullOrEmpty(menu.TargetViewKey))
{
return;
}
var mainViewModel = App.Current.Services.GetRequiredService<MainViewModel>();
var viewModel = GetViewModelByKey(viewKey);
var viewModel = GetViewModelByKey(menu.TargetViewKey);
if (viewModel is INavigatable navigatableViewModel)
{
await navigatableViewModel.OnNavigatedToAsync(parameter);
await navigatableViewModel.OnNavigatedToAsync(menu);
}
mainViewModel.CurrentViewModel = viewModel;