InkCanvasForClass/Ink Canvas/MainWindow_cs/MW_Notification.cs

33 lines
1.2 KiB
C#

using Ink_Canvas.Helpers;
using System;
using System.Linq;
using System.Threading;
using System.Windows;
namespace Ink_Canvas {
public partial class MainWindow : Window {
int lastNotificationShowTime = 0;
int notificationShowTime = 2500;
public static void ShowNewMessage(string notice, bool isShowImmediately = true) {
(Application.Current?.Windows.Cast<Window>().FirstOrDefault(window => window is MainWindow) as MainWindow)?.ShowNotification(notice, isShowImmediately);
}
public void ShowNotification(string notice, bool isShowImmediately = true) {
lastNotificationShowTime = Environment.TickCount;
TextBlockNotice.Text = notice;
AnimationsHelper.ShowWithFadeIn(GridNotifications);
new Thread(new ThreadStart(() => {
Thread.Sleep(notificationShowTime + 300);
if (Environment.TickCount - lastNotificationShowTime >= notificationShowTime) {
Application.Current.Dispatcher.Invoke(() => {
AnimationsHelper.HideWithFadeOut(GridNotifications);
});
}
})).Start();
}
}
}