diff options
Diffstat (limited to 'Software/Visual_Studio/StubsUtils/Notifications.Wpf/NotificationManager.cs')
| -rw-r--r-- | Software/Visual_Studio/StubsUtils/Notifications.Wpf/NotificationManager.cs | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/Software/Visual_Studio/StubsUtils/Notifications.Wpf/NotificationManager.cs b/Software/Visual_Studio/StubsUtils/Notifications.Wpf/NotificationManager.cs new file mode 100644 index 000000000..0e8091e8a --- /dev/null +++ b/Software/Visual_Studio/StubsUtils/Notifications.Wpf/NotificationManager.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Windows; +using System.Windows.Threading; +using Notifications.Wpf.Controls; + +namespace Notifications.Wpf +{ + public class NotificationManager : INotificationManager + { + private readonly Dispatcher _dispatcher; + private static readonly List<NotificationArea> Areas = new List<NotificationArea>(); + private static NotificationsOverlayWindow _window; + + public NotificationManager(Dispatcher dispatcher = null) + { + if (dispatcher == null) + { + dispatcher = Application.Current?.Dispatcher ?? Dispatcher.CurrentDispatcher; + } + + _dispatcher = dispatcher; + } + + public void Show(object content, string areaName = "", TimeSpan? expirationTime = null, Action onClick = null, + Action onClose = null) + { + if (!_dispatcher.CheckAccess()) + { + _dispatcher.BeginInvoke( + new Action(() => Show(content, areaName, expirationTime, onClick, onClose))); + return; + } + + if (expirationTime == null) expirationTime = TimeSpan.FromSeconds(5); + + if (areaName == string.Empty && _window == null) + { + var workArea = SystemParameters.WorkArea; + + _window = new NotificationsOverlayWindow + { + Left = workArea.Left, + Top = workArea.Top, + Width = workArea.Width, + Height = workArea.Height + }; + + _window.Show(); + } + + foreach (var area in Areas.Where(a => a.Name == areaName)) + { + area.Show(content, (TimeSpan) expirationTime, onClick, onClose); + } + } + + internal static void AddArea(NotificationArea area) + { + Areas.Add(area); + } + } +}
\ No newline at end of file |
