|
@@ -13,181 +13,188 @@ using System.Windows.Input;
|
|
|
|
|
|
namespace IViewModel.ViewModels
|
|
|
{
|
|
|
- public abstract class DisplayViewModelBase<TModel>:ViewModelBase<TModel> where TModel :IModel.IModel
|
|
|
- { public DisplayViewModelBase() : base() { }
|
|
|
- public DisplayViewModelBase(TModel model):base(model) { }
|
|
|
- private protected virtual string Caption=>LanguageValueViewModel.Instance.PromptTitle;
|
|
|
- private protected virtual string Yes =>LanguageValueViewModel.Instance.PromptYes;
|
|
|
- private protected virtual string No =>LanguageValueViewModel.Instance.PromptNo;
|
|
|
- public virtual double Width => double.NaN;
|
|
|
- public virtual double Height => double.NaN;
|
|
|
- public virtual bool CanResize => true;
|
|
|
- [AllowNull]
|
|
|
- public Action CloseWindowAction { get; set; }
|
|
|
- public ISukiToastManager ToastManager { get; } = new SukiToastManager();
|
|
|
- public ISukiDialogManager DialogManager { get; } = new SukiDialogManager();
|
|
|
- [AllowNull]
|
|
|
- public virtual Type Content
|
|
|
- {
|
|
|
- get => content;
|
|
|
- set => SetProperty(ref content , value);
|
|
|
- }
|
|
|
- private string title = string.Empty;
|
|
|
- private bool saveIsEnabled= false;
|
|
|
|
|
|
- public bool SaveIsEnabled
|
|
|
+ public abstract class DisplayViewModelBase<TModel> :ViewModelBase<TModel>,IDisplayViewModel where TModel : IModel.IModel
|
|
|
{
|
|
|
- get { return saveIsEnabled; }
|
|
|
- set {SetProperty(ref saveIsEnabled , value); }
|
|
|
- }
|
|
|
- [AllowNull]
|
|
|
- public virtual bool CanCancel { get; } = typeof(TModel).IsAnsiClass && !typeof(TModel).IsAbstract;
|
|
|
+ public virtual bool ShowTop { get; } = false;
|
|
|
+
|
|
|
+ public virtual bool AppendSeparator { get; }
|
|
|
+ public virtual string MenuKey { get; } = string.Empty;
|
|
|
+ public virtual string MenuParentKey { get; } = string.Empty;
|
|
|
+ public DisplayViewModelBase() : base() { }
|
|
|
+ public DisplayViewModelBase(TModel model) : base(model) { }
|
|
|
+ private protected virtual string Caption => LanguageValueViewModel.Instance.PromptTitle;
|
|
|
+ private protected virtual string Yes => LanguageValueViewModel.Instance.PromptYes;
|
|
|
+ private protected virtual string No => LanguageValueViewModel.Instance.PromptNo;
|
|
|
+ public virtual double Width => double.NaN;
|
|
|
+ public virtual double Height => double.NaN;
|
|
|
+ public virtual bool CanResize => true;
|
|
|
+ [AllowNull]
|
|
|
+ public Action CloseWindowAction { get; set; }
|
|
|
+ public ISukiToastManager ToastManager { get; } = new SukiToastManager();
|
|
|
+ public ISukiDialogManager DialogManager { get; } = new SukiDialogManager();
|
|
|
+ [AllowNull]
|
|
|
+ public virtual Type Content
|
|
|
+ {
|
|
|
+ get => content;
|
|
|
+ set => SetProperty(ref content, value);
|
|
|
+ }
|
|
|
+ private string title = string.Empty;
|
|
|
+ private bool saveIsEnabled = false;
|
|
|
|
|
|
+ public bool SaveIsEnabled
|
|
|
+ {
|
|
|
+ get { return saveIsEnabled; }
|
|
|
+ set { SetProperty(ref saveIsEnabled, value); }
|
|
|
+ }
|
|
|
+ [AllowNull]
|
|
|
+ public virtual bool CanCancel { get; } = typeof(TModel).IsAnsiClass && !typeof(TModel).IsAbstract;
|
|
|
|
|
|
- public bool ShowError(string msg)
|
|
|
- {
|
|
|
-
|
|
|
- return DispatherInovke.Inovke(()=> DialogManager.CreateDialog()
|
|
|
- .OfType(Avalonia.Controls.Notifications.NotificationType.Error)
|
|
|
- .WithTitle(Caption)
|
|
|
- .WithContent(msg)
|
|
|
- .WithActionButton
|
|
|
- (Yes, _ => { }, true).TryShow());
|
|
|
- }
|
|
|
- public bool ShowAsk(string msg, Action? yesaction = null, Action? noaction = null)
|
|
|
- {
|
|
|
- return DispatherInovke.Inovke(()=> DialogManager.CreateDialog()
|
|
|
- .OfType(Avalonia.Controls.Notifications.NotificationType.Information)
|
|
|
- .WithTitle(Caption)
|
|
|
- .WithContent(msg)
|
|
|
- .WithActionButton(Yes, _ => yesaction?.Invoke(), true)
|
|
|
- .WithActionButton(No, _ => noaction?.Invoke(), true)
|
|
|
- .TryShow());
|
|
|
- }
|
|
|
- public bool ShowInfo(string msg)
|
|
|
- {
|
|
|
- return DispatherInovke.Inovke(()=> DialogManager.CreateDialog()
|
|
|
- .OfType(Avalonia.Controls.Notifications.NotificationType.Information)
|
|
|
- .WithTitle(Caption)
|
|
|
- .WithContent(msg)
|
|
|
- .WithActionButton
|
|
|
- (Yes, _ => { }, true).TryShow());
|
|
|
- }
|
|
|
- public bool ShowSuccess(string msg)
|
|
|
- {
|
|
|
- return DispatherInovke.Inovke(()=> DialogManager.CreateDialog()
|
|
|
- .OfType(Avalonia.Controls.Notifications.NotificationType.Success)
|
|
|
- .WithTitle(Caption)
|
|
|
- .WithContent(msg)
|
|
|
- .WithActionButton
|
|
|
- (Yes, _ => { }, true).TryShow());
|
|
|
- }
|
|
|
- public bool ShowWarning(string msg)
|
|
|
- {
|
|
|
- return DispatherInovke.Inovke(()=> DialogManager.CreateDialog()
|
|
|
- .OfType(Avalonia.Controls.Notifications.NotificationType.Warning)
|
|
|
- .WithTitle(Caption)
|
|
|
- .WithContent(msg)
|
|
|
- .WithActionButton
|
|
|
- (Yes, _ => { }, true).TryShow());
|
|
|
- }
|
|
|
|
|
|
+ public bool ShowError(string msg)
|
|
|
+ {
|
|
|
|
|
|
- public void ShowToast(string msg,Avalonia.Controls.Notifications.NotificationType type = Avalonia.Controls.Notifications.NotificationType.Information)
|
|
|
- {
|
|
|
- if (ToastManager == null) return;
|
|
|
- DispatherInovke.Inovke(()=> ToastManager.CreateToast()
|
|
|
- .WithTitle(Caption)
|
|
|
- .WithContent(msg)
|
|
|
- .OfType(type)
|
|
|
- .Dismiss().After(TimeSpan.FromSeconds(3))
|
|
|
- .Dismiss().ByClicking()
|
|
|
- .Queue());
|
|
|
- }
|
|
|
- private protected bool cansave = false;
|
|
|
+ return DispatherInovke.Inovke(() => DialogManager.CreateDialog()
|
|
|
+ .OfType(Avalonia.Controls.Notifications.NotificationType.Error)
|
|
|
+ .WithTitle(Caption)
|
|
|
+ .WithContent(msg)
|
|
|
+ .WithActionButton
|
|
|
+ (Yes, _ => { }, true).TryShow());
|
|
|
+ }
|
|
|
+ public bool ShowAsk(string msg, Action? yesaction = null, Action? noaction = null)
|
|
|
+ {
|
|
|
+ return DispatherInovke.Inovke(() => DialogManager.CreateDialog()
|
|
|
+ .OfType(Avalonia.Controls.Notifications.NotificationType.Information)
|
|
|
+ .WithTitle(Caption)
|
|
|
+ .WithContent(msg)
|
|
|
+ .WithActionButton(Yes, _ => yesaction?.Invoke(), true)
|
|
|
+ .WithActionButton(No, _ => noaction?.Invoke(), true)
|
|
|
+ .TryShow());
|
|
|
+ }
|
|
|
+ public bool ShowInfo(string msg)
|
|
|
+ {
|
|
|
+ return DispatherInovke.Inovke(() => DialogManager.CreateDialog()
|
|
|
+ .OfType(Avalonia.Controls.Notifications.NotificationType.Information)
|
|
|
+ .WithTitle(Caption)
|
|
|
+ .WithContent(msg)
|
|
|
+ .WithActionButton
|
|
|
+ (Yes, _ => { }, true).TryShow());
|
|
|
+ }
|
|
|
+ public bool ShowSuccess(string msg)
|
|
|
+ {
|
|
|
+ return DispatherInovke.Inovke(() => DialogManager.CreateDialog()
|
|
|
+ .OfType(Avalonia.Controls.Notifications.NotificationType.Success)
|
|
|
+ .WithTitle(Caption)
|
|
|
+ .WithContent(msg)
|
|
|
+ .WithActionButton
|
|
|
+ (Yes, _ => { }, true).TryShow());
|
|
|
+ }
|
|
|
+ public bool ShowWarning(string msg)
|
|
|
+ {
|
|
|
+ return DispatherInovke.Inovke(() => DialogManager.CreateDialog()
|
|
|
+ .OfType(Avalonia.Controls.Notifications.NotificationType.Warning)
|
|
|
+ .WithTitle(Caption)
|
|
|
+ .WithContent(msg)
|
|
|
+ .WithActionButton
|
|
|
+ (Yes, _ => { }, true).TryShow());
|
|
|
+ }
|
|
|
|
|
|
- public virtual string OKContent => "Save";
|
|
|
- public virtual string CancelContent =>"Cancel";
|
|
|
|
|
|
+ public void ShowToast(string msg, Avalonia.Controls.Notifications.NotificationType type = Avalonia.Controls.Notifications.NotificationType.Information)
|
|
|
+ {
|
|
|
+ if (ToastManager == null) return;
|
|
|
+ DispatherInovke.Inovke(() => ToastManager.CreateToast()
|
|
|
+ .WithTitle(Caption)
|
|
|
+ .WithContent(msg)
|
|
|
+ .OfType(type)
|
|
|
+ .Dismiss().After(TimeSpan.FromSeconds(3))
|
|
|
+ .Dismiss().ByClicking()
|
|
|
+ .Queue());
|
|
|
+ }
|
|
|
+ private protected bool cansave = false;
|
|
|
|
|
|
- public bool SaveClose { get => saveClose; set =>SetProperty(ref saveClose , value); }
|
|
|
- public ICommand SaveCommand => new RelayCommand(async ()=>
|
|
|
- {
|
|
|
- if (!cansave) return;
|
|
|
- Save();
|
|
|
- if(!savecanclose)
|
|
|
+ public virtual string OKContent => "Save";
|
|
|
+ public virtual string CancelContent => "Cancel";
|
|
|
+
|
|
|
+
|
|
|
+ public bool SaveClose { get => saveClose; set => SetProperty(ref saveClose, value); }
|
|
|
+ public ICommand SaveCommand => new RelayCommand(async () =>
|
|
|
{
|
|
|
- cansave = true;
|
|
|
- SaveClose = false;
|
|
|
- await Task.Delay(2);
|
|
|
- await Task.Run(() =>
|
|
|
+ if (!cansave) return;
|
|
|
+ Save();
|
|
|
+ if (!savecanclose)
|
|
|
{
|
|
|
- DispatherInovke.Inovke(() => SaveClose = true);
|
|
|
- });
|
|
|
- return;
|
|
|
+ cansave = true;
|
|
|
+ SaveClose = false;
|
|
|
+ await Task.Delay(2);
|
|
|
+ await Task.Run(() =>
|
|
|
+ {
|
|
|
+ DispatherInovke.Inovke(() => SaveClose = true);
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ cansave = false;
|
|
|
+ });
|
|
|
+ public ICommand CancelCommand => new RelayCommand(Cancel);
|
|
|
+
|
|
|
+ public virtual string Title { get => title; set => SetProperty(ref title, value); }
|
|
|
+ public bool ButtonVisibily { get => buttonVisibily; set => SetProperty(ref buttonVisibily, value); }
|
|
|
+ private protected bool savecanclose = true;
|
|
|
+ protected virtual void Save()
|
|
|
+ {
|
|
|
+ lastModel = default;
|
|
|
+ savecanclose = true;
|
|
|
}
|
|
|
- cansave = false;
|
|
|
- });
|
|
|
- public ICommand CancelCommand => new RelayCommand(Cancel);
|
|
|
-
|
|
|
- public virtual string Title { get => title; set =>SetProperty(ref title , value); }
|
|
|
- public bool ButtonVisibily { get => buttonVisibily; set =>SetProperty(ref buttonVisibily , value); }
|
|
|
- private protected bool savecanclose = true;
|
|
|
- protected virtual void Save()
|
|
|
- {
|
|
|
- lastModel = default;
|
|
|
- savecanclose = true;
|
|
|
- }
|
|
|
|
|
|
- [AllowNull]
|
|
|
- private Type content;
|
|
|
+ [AllowNull]
|
|
|
+ private Type content;
|
|
|
|
|
|
- public virtual void InitData()
|
|
|
- {
|
|
|
- SaveClose = true;
|
|
|
- cansave = true;
|
|
|
- if (CanCancel)
|
|
|
+ public virtual void InitData()
|
|
|
+ {
|
|
|
+ SaveClose = true;
|
|
|
+ cansave = true;
|
|
|
+ if (CanCancel)
|
|
|
+ {
|
|
|
+ lastModel = (TModel)Model.Clone();
|
|
|
+ SaveIsEnabled = false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //lastModel = default;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected virtual bool SkipProperty(string? propertyName)
|
|
|
{
|
|
|
- lastModel = (TModel)Model.Clone();
|
|
|
- SaveIsEnabled = false;
|
|
|
+ return false;
|
|
|
}
|
|
|
- else
|
|
|
+ protected override void OnPropertyChanged(PropertyChangedEventArgs e)
|
|
|
{
|
|
|
- //lastModel = default;
|
|
|
+ if (e.PropertyName != nameof(SaveClose)) SaveClose = true;
|
|
|
+ base.OnPropertyChanged(e);
|
|
|
+ if (e.PropertyName == nameof(Content)
|
|
|
+ || e.PropertyName == nameof(Model)
|
|
|
+ || e.PropertyName == nameof(ButtonVisibily)
|
|
|
+ || e.PropertyName == nameof(SaveCommand)
|
|
|
+ || e.PropertyName == nameof(Title)
|
|
|
+ || e.PropertyName == nameof(SaveIsEnabled)
|
|
|
+ || e.PropertyName == nameof(CancelCommand))
|
|
|
+ return;
|
|
|
+ if (SkipProperty(e.PropertyName)) return;
|
|
|
+ SaveIsEnabled = true;
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- protected virtual bool SkipProperty(string? propertyName)
|
|
|
- {
|
|
|
- return false;
|
|
|
- }
|
|
|
- protected override void OnPropertyChanged(PropertyChangedEventArgs e)
|
|
|
- {
|
|
|
- if(e.PropertyName !=nameof(SaveClose)) SaveClose = true;
|
|
|
- base.OnPropertyChanged(e);
|
|
|
- if (e.PropertyName == nameof(Content)
|
|
|
- || e.PropertyName == nameof(Model)
|
|
|
- || e.PropertyName == nameof(ButtonVisibily)
|
|
|
- || e.PropertyName == nameof(SaveCommand)
|
|
|
- || e.PropertyName == nameof(Title)
|
|
|
- || e.PropertyName == nameof(SaveIsEnabled)
|
|
|
- || e.PropertyName == nameof(CancelCommand))
|
|
|
- return;
|
|
|
- if (SkipProperty(e.PropertyName)) return;
|
|
|
- SaveIsEnabled = true;
|
|
|
- }
|
|
|
|
|
|
|
|
|
- private bool buttonVisibily = true;
|
|
|
- private bool saveClose = true;
|
|
|
+ private bool buttonVisibily = true;
|
|
|
+ private bool saveClose = true;
|
|
|
|
|
|
- protected virtual void Cancel()
|
|
|
- {
|
|
|
- if (CanCancel && lastModel !=null)
|
|
|
+ protected virtual void Cancel()
|
|
|
{
|
|
|
- UpDateModel(lastModel);
|
|
|
- lastModel = default;
|
|
|
+ if (CanCancel && lastModel != null)
|
|
|
+ {
|
|
|
+ UpDateModel(lastModel);
|
|
|
+ lastModel = default;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
}
|