using DownKyi.Images; using DownKyi.Models; using DownKyi.Utils; using Prism.Commands; using Prism.Mvvm; using Prism.Services.Dialogs; using System; namespace DownKyi.ViewModels.Dialogs { public class BaseDialogViewModel : BindableBase, IDialogAware { #region 页面属性申明 private string title; public string Title { get { return title; } set { SetProperty(ref title, value); } } private VectorImage closeIcon; public VectorImage CloseIcon { get { return 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 ?? (closeEnterCommand = new DelegateCommand(ExecuteCloseEnterCommand)); /// /// 鼠标进入关闭按钮事件 /// private void ExecuteCloseEnterCommand() { SetEnterStyle(CloseIcon); } // 鼠标离开关闭按钮事件 private DelegateCommand closeLeaveCommand; public DelegateCommand CloseLeaveCommand => closeLeaveCommand ?? (closeLeaveCommand = new DelegateCommand(ExecuteCloseLeaveCommand)); /// /// 鼠标离开关闭按钮事件 /// private void ExecuteCloseLeaveCommand() { SetLeaveStyle(CloseIcon); } // 关闭窗口事件 private DelegateCommand closeCommand; public DelegateCommand CloseCommand => closeCommand ?? (closeCommand = new DelegateCommand(ExecuteCloseCommand)); /// /// 关闭窗口事件 /// private void ExecuteCloseCommand() { ButtonResult result = ButtonResult.Cancel; RaiseRequestClose(new DialogResult(result)); } #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 } }