using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Timers; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; namespace ivf_tl_Manage.Win { /// /// ToastMessageWindow.xaml 的交互逻辑 /// public partial class ToastMessageWindow : Window { private Window parent = null; public System.Timers.Timer timer; public ToastMessageWindow(Window w, double viewWidth, double top, string message) { InitializeComponent(); this._message.Text = message; timer = new System.Timers.Timer(1500); timer.Enabled = false; timer.AutoReset = false; timer.Elapsed += timer_Elapsed; var a = this.ActualWidth; this.Owner = w; this.Width = a; this.parent = w; Loaded += (a, b) => { this.Top = top; this.Left = (viewWidth / 2) - (this.ActualWidth / 2); }; this.Closed += (a, b) => { if (parent != null) { parent.Activate(); } }; timer.Start(); } public ToastMessageWindow(Window w, string message) { InitializeComponent(); this._message.Text = message; timer = new System.Timers.Timer(1500); timer.Enabled = false; timer.AutoReset = false; timer.Elapsed += timer_Elapsed; var a = this.ActualWidth; this.Owner = w; this.Width = a; this.parent = w; this.WindowStartupLocation = WindowStartupLocation.CenterOwner; this.Closed += (a, b) => { if (parent != null) { parent.Activate(); } }; timer.Start(); } private void timer_Elapsed(object? sender, ElapsedEventArgs e) { timer.Stop(); timer.Enabled = false; timer.Close(); timer.Dispose(); Dispatcher.Invoke(() => { this.Close(); }); } } }