| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- using System;
- using Prism.Mvvm;
- using System.Linq;
- using Prism.Events;
- using Prism.Regions;
- using Prism.Commands;
- using Panuon.UI.Silver;
- using System.Windows.Controls;
- using SHJX.Service.Common.Event;
- using System.Collections.Generic;
- using SHJX.Service.Common.Constants;
- using SHJX.Service.Common.Interface;
- using SHJX.Service.Control.Interface;
- using System.Collections.ObjectModel;
- namespace SHJX.Service.Shell.ViewModels.Setting
- {
- public class SettingWindowViewModel : BindableBase
- {
- #region Field
- private IRegion _region;
- private readonly ILogService _log;
- private readonly IEventAggregator _ea;
- private readonly ISettingService _service;
- private readonly IRegionManager _regionManager;
- private Dictionary<string, string> _items;
- #endregion
- #region Property
- public ObservableCollection<TabItem> TabItemInfos { get; set; }
- private bool? _dialogResult;
- public bool? DialogResult
- {
- get { return _dialogResult; }
- set => SetProperty(ref _dialogResult, value);
- }
- #endregion
- public SettingWindowViewModel(IEventAggregator ea, IRegionManager regionManager, ILogService log, ISettingService service)
- {
- _ea = ea;
- _log = log;
- _service = service;
- _regionManager = regionManager;
- TabItemInfos ??= new ObservableCollection<TabItem>();
- InitDataAndBind();
- }
- #region Command
- private DelegateCommand _loginLoadingCommand;
- public DelegateCommand LoginLoadingCommand => _loginLoadingCommand ??= new DelegateCommand(ExecuteLoginLoadingCommand);
- private DelegateCommand<string> _menuSelectionChangedCommand;
- public DelegateCommand<string> MenuSelectionChangedCommand => _menuSelectionChangedCommand ??= new DelegateCommand<string>(ExecuteMenuSelectionChangedCommand);
- private DelegateCommand _closingCommand;
- public DelegateCommand ClosingCommand => _closingCommand ??= new DelegateCommand(() =>
- {
- _ea.GetEvent<SettingClosingEvent>().Publish();
- _regionManager.Regions.Remove(RegionNames.SettingRegion);//关闭窗体之前先移除注册项
- });
- private DelegateCommand _updateSettingCommand;
- public DelegateCommand UpdateSettingCommand => _updateSettingCommand ??= new DelegateCommand(() =>
- {
- _ea.GetEvent<UpdateSettingEvent>().Publish();
- });
- private DelegateCommand _cancelSettingUpdate;
- public DelegateCommand CancelSettingUpdate => _cancelSettingUpdate ??= new DelegateCommand(() =>
- {
- DialogResult = true;
- });
- #endregion
- #region Execute
- void ExecuteLoginLoadingCommand()
- {
- try
- {
- _region = _regionManager.Regions[RegionNames.SettingRegion];
- _region.RequestNavigate(_items.FirstOrDefault().Value);
- }
- catch (Exception ex)
- {
- _log.ErrorFormat(ex.ToString());
- }
- }
- public void ExecuteMenuSelectionChangedCommand(string elementName)
- {
- try
- {
- if (_items.TryGetValue(elementName, out var value))
- {
- _region.RequestNavigate(value);
- }
- }
- catch (Exception ex)
- {
- _log.ErrorFormat(ex.ToString());
- }
- }
- #endregion
- #region Method
- private void InitDataAndBind()
- {
- _items = _service.SettingTabItems;
- foreach (var item in _items.Keys)
- {
- TabItem tab = new()
- {
- Header = item
- };
- TabItemInfos.Add(tab);
- }
- }
- #endregion
- }
- }
|