123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- using HandyControl.Interactivity.Commands;
- using Shaker.ViewModel;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics.CodeAnalysis;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Timers;
- using System.Windows;
- using System.Windows.Input;
- using System.Windows.Media;
- namespace ShakerControl.ViewModel
- {
- internal class PromptViewModel:ViewModelBase<Shaker.Model.ModelBase>
- {
- static PromptViewModel()
- {
- }
- private uint maxcount = 0;
- private uint consumetime = 0;
- private PromptViewModel()
- {
- timer.Stop();
- timer.Interval = 1000;
- timer.AutoReset = true;
- timer.Elapsed += (sender, e) =>
- {
- consumetime++;
- Tools.DispatherInovke.Inovke(() =>
- {
- if (YesTextFunc != null)
- {
- YesText = YesTextFunc(consumetime);
- }
- if (NoTextFunc != null)
- {
- NoText = NoTextFunc(consumetime);
- }
- if (consumetime >= maxcount)
- {
- IsOpen = false;
- timer.Stop();
- }
- });
- };
- }
- public override void Init()
- {
- base.Init();
- maxcount = 0;
- consumetime = 0;
- timer.Stop();
- YesTextFunc = null;
- NoTextFunc = null;
- YesVisibility = Visibility.Visible;
- NoVisibility = Visibility.Visible;
- YesText = "是";
- NoText = "否";
- Title = "提示";
- Message = "请确认";
- YesAction = null;
- NoAction = null;
- IsOpen = false;
- IconType = IconType.Info;
- }
- public static PromptViewModel Default { get; } = new PromptViewModel();
-
- public Visibility IconVisibility { get => iconVisibility; set =>UpdateProperty(ref iconVisibility, value); }
- public IconType IconType
- {
- get => iconType;
- set
- {
- if (value != iconType)
- {
- iconType = value;
- }
- switch (iconType)
- {
- case IconType.Info:
- default:
- IconGeometry = (Geometry)App.Current.FindResource("InfoGeometry");
- IconBrush = new SolidColorBrush(Colors.Black);
- break;
- case IconType.Ask:
- IconGeometry = (Geometry)App.Current.FindResource("AskGeometry");
- IconBrush = new SolidColorBrush(Colors.DarkOrange);
- break;
- case IconType.Error:
- IconGeometry = (Geometry)App.Current.FindResource("ErrorGeometry");
- IconBrush = new SolidColorBrush(Colors.Red);
- break;
- }
- }
- }
- private SolidColorBrush iconBrush = new SolidColorBrush(Colors.Black);
- public SolidColorBrush IconBrush { get => iconBrush; set =>UpdateProperty(ref iconBrush, value); }
- public Geometry IconGeometry { get => iconGeometry; set =>UpdateProperty(ref iconGeometry, value); }
- [AllowNull]
- public Action YesAction { get; set; }
- [AllowNull]
- public Action NoAction { get; set; }
- private bool isOpen = false;
- private string title = "提示";
- private string message = "请确认";
- private string yesText = "是";
- private string noText = "否";
- private Visibility yesVisibility = Visibility.Visible;
- private Visibility noVisibility = Visibility.Visible;
- private Visibility iconVisibility = Visibility.Visible;
- private IconType iconType = IconType.Info;
- private Geometry iconGeometry = (Geometry)App.Current.FindResource("InfoGeometry");
- private System.Timers.Timer timer = new System.Timers.Timer();
- [AllowNull]
- public Func<uint,string> YesTextFunc { get; set; }
- [AllowNull]
- public Func<uint, string> NoTextFunc { get; set; }
- public void SetTimeout(uint timeout)
- {
- consumetime = 0;
- maxcount = timeout;
- timer.AutoReset = true;
- timer.Start();
- }
- public bool IsOpen { get => isOpen; set =>UpdateProperty(ref isOpen, value); }
- public string Title { get => title; set =>UpdateProperty(ref title, value); }
- public string Message { get => message; set =>UpdateProperty( ref message , value); }
- public string YesText { get => yesText; set =>UpdateProperty(ref yesText, value); }
- public string NoText { get => noText; set =>UpdateProperty(ref noText,value); }
- public ICommand YesCommand => new DelegateCommand(() =>
- {
- IsOpen = false;
- YesAction?.Invoke();
- });
- public ICommand NoCommand => new DelegateCommand(() =>
- {
- IsOpen = false;
- NoAction?.Invoke();
- });
- public Visibility YesVisibility { get => yesVisibility; set =>UpdateProperty(ref yesVisibility, value); }
- public Visibility NoVisibility { get => noVisibility; set =>UpdateProperty(ref noVisibility,value); }
- }
- }
|