给菜单添加TargetViewKey
This commit is contained in:
@@ -56,6 +56,7 @@ public partial class DataServices : ObservableRecipient, IRecipient<LoadMessage>
|
||||
|
||||
public ConcurrentDictionary<int, Variable> AllVariables;
|
||||
private readonly IMenuService _menuService;
|
||||
private readonly INavigationService _navigationService;
|
||||
|
||||
|
||||
// 设备列表变更事件,当设备列表数据更新时触发。
|
||||
@@ -79,13 +80,14 @@ public partial class DataServices : ObservableRecipient, IRecipient<LoadMessage>
|
||||
/// <param name="mapper">AutoMapper 实例。</param>
|
||||
/// <param name="varDataRepository"></param>
|
||||
public DataServices(IMapper mapper, IDeviceAppService deviceAppService,
|
||||
IVariableTableAppService variableTableAppService, IVariableAppService variableAppService,IMenuService menuService)
|
||||
IVariableTableAppService variableTableAppService, IVariableAppService variableAppService,IMenuService menuService,INavigationService navigationService)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_deviceAppService = deviceAppService;
|
||||
_variableTableAppService = variableTableAppService;
|
||||
_variableAppService = variableAppService;
|
||||
_menuService = menuService;
|
||||
_navigationService = navigationService;
|
||||
IsActive = true; // 激活消息接收器
|
||||
Devices = new ObservableCollection<DeviceItemViewModel>();
|
||||
VariableTables = new ObservableCollection<VariableTableItemViewModel>();
|
||||
@@ -246,7 +248,7 @@ public partial class DataServices : ObservableRecipient, IRecipient<LoadMessage>
|
||||
{
|
||||
// 这是一个新菜单项,添加到集合中
|
||||
// 注意:这里直接添加 IMenuService 返回的 MenuItemViewModel 实例
|
||||
Menus.Add(_mapper.Map<MenuBeanItemViewModel>(newDto));
|
||||
Menus.Add(new MenuBeanItemViewModel(newDto,_navigationService));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows.Input;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using DMS.Application.DTOs;
|
||||
using DMS.Core.Enums;
|
||||
using DMS.WPF.Services;
|
||||
|
||||
namespace DMS.WPF.ViewModels.Items;
|
||||
|
||||
@@ -23,6 +26,8 @@ public partial class MenuBeanItemViewModel : ObservableObject
|
||||
|
||||
[ObservableProperty]
|
||||
private int _targetId;
|
||||
[ObservableProperty]
|
||||
private string _targetViewKey;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _navigationParameter;
|
||||
@@ -31,16 +36,26 @@ public partial class MenuBeanItemViewModel : ObservableObject
|
||||
private int _displayOrder;
|
||||
[ObservableProperty]
|
||||
private ObservableCollection<MenuBeanItemViewModel> _children=new ();
|
||||
|
||||
/// <summary>
|
||||
/// 菜单项点击时执行的导航命令。
|
||||
/// </summary>
|
||||
public ICommand NavigateCommand { get; }
|
||||
|
||||
public MenuBeanItemViewModel(MenuBeanDto dto)
|
||||
public MenuBeanItemViewModel(MenuBeanDto dto,INavigationService navigationService)
|
||||
{
|
||||
Id = dto.Id;
|
||||
_parentId = dto.ParentId;
|
||||
_header = dto.Header;
|
||||
_icon = dto.Icon;
|
||||
_menuType = dto.MenuType;
|
||||
_targetViewKey=dto.TargetViewKey;
|
||||
_targetId = dto.TargetId;
|
||||
_navigationParameter = dto.NavigationParameter;
|
||||
_displayOrder = dto.DisplayOrder;
|
||||
NavigateCommand = new AsyncRelayCommand(async () =>
|
||||
{
|
||||
await navigationService.NavigateToAsync(_targetViewKey, _navigationParameter);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
<DataTemplate x:Key="NavigationViewMenuItem"
|
||||
DataType="{x:Type mo:MenuBean}">
|
||||
<ui:NavigationViewItem Content="{Binding Header}"
|
||||
|
||||
MenuItemsSource="{Binding Children }">
|
||||
<ui:NavigationViewItem.Icon>
|
||||
<ui:FontIcon Glyph="{Binding Icon}" />
|
||||
|
||||
Reference in New Issue
Block a user