using System; using DownKyi.Images; using DownKyi.Models; using DownKyi.Utils; using Prism.Commands; using Prism.Mvvm; using Prism.Services.Dialogs; namespace DownKyi.ViewModels.Dialogs; public class BaseDialogViewModel : BindableBase, IDialogAware { #region 页面属性申明 private string _title; public string Title { get => _title; set => SetProperty(ref _title, value); } private VectorImage _closeIcon; public VectorImage CloseIcon { get => _closeIcon; set => SetProperty(ref _closeIcon, value); } #endregion public BaseDialogViewModel() { #region 属性初始化 Title = new AppInfo().Name; CloseIcon = new VectorImage { Height = SystemIcon.Instance().Close.Height, Width = SystemIcon.Instance().Close.Width, Data = SystemIcon.Instance().Close.Data, Fill = SystemIcon.Instance().Close.Fill }; #endregion } #region 命令申明 // 鼠标进入关闭按钮事件 private DelegateCommand? _closeEnterCommand; public DelegateCommand CloseEnterCommand => _closeEnterCommand ??= new DelegateCommand(ExecuteCloseEnterCommand); /// /// 鼠标进入关闭按钮事件 /// private void ExecuteCloseEnterCommand() { SetEnterStyle(CloseIcon); } // 鼠标离开关闭按钮事件 private DelegateCommand? _closeLeaveCommand; public DelegateCommand CloseLeaveCommand => _closeLeaveCommand ??= new DelegateCommand(ExecuteCloseLeaveCommand); /// /// 鼠标离开关闭按钮事件 /// private void ExecuteCloseLeaveCommand() { SetLeaveStyle(CloseIcon); } // 关闭窗口事件 private DelegateCommand? _closeCommand; public DelegateCommand CloseCommand => _closeCommand ??= new DelegateCommand(ExecuteCloseCommand); /// /// 关闭窗口事件 /// private void ExecuteCloseCommand() { RaiseRequestClose(new DialogResult(ButtonResult.Cancel)); } #endregion /// /// 鼠标进入系统按钮时的图标样式 /// /// 图标 private void SetEnterStyle(VectorImage icon) { icon.Fill = DictionaryResource.GetColor("ColorSystemBtnTint"); } /// /// 鼠标离开系统按钮时的图标样式 /// /// 图标 private void SetLeaveStyle(VectorImage icon) { icon.Fill = DictionaryResource.GetColor("ColorSystemBtnTintDark"); } #region 接口实现 //触发窗体关闭事件 public virtual void RaiseRequestClose(IDialogResult dialogResult) { RequestClose?.Invoke(dialogResult); } public event Action RequestClose; public virtual bool CanCloseDialog() { return true; } public virtual void OnDialogClosed() { } public virtual void OnDialogOpened(IDialogParameters parameters) { } #endregion }