-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathNotification.cs
More file actions
69 lines (61 loc) · 2.17 KB
/
Copy pathNotification.cs
File metadata and controls
69 lines (61 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System.Collections.Generic;
using System.Threading.Tasks;
using SkillChat.Client.Notification.ViewModels;
using Splat;
namespace SkillChat.Client.ViewModel
{
public class Notification
{
private const int DefaultNotificationDurationMs = 10000;
private static Notification _manager;
private List<INotify> _notificationWindows = new List<INotify>();
//Добавление увдеомлений в очередь
private void Add(INotify window)
{
_notificationWindows.Insert(0,window);
Reposition();
}
//Переопределение позиции окна
private void Reposition()
{
int count = 0;
foreach (var window in _notificationWindows)
{
if (!window.IsClosed)
{
count++;
window.SetPosition(window.ScreenBottomRightX - (int)(window.Width*window.PrimaryPixelDensity),
window.ScreenBottomRightY - count * (int)(window.Height* window.PrimaryPixelDensity) - (int)(window.PrimaryPixelDensity) -(int) (10 * window.PrimaryPixelDensity)*count);
}
}
}
public static Notification Manager
{
get { return _manager ?? (_manager = new Notification()); }
}
//Вызов окна
public async void Show(string title, string text, int? timeShow = DefaultNotificationDurationMs)
{
var w = Locator.Current.GetService<INotify>();
w.ShowInTaskbar = false;
w.Topmost = true;
w.DataContext = new NotifyViewModel(title, text, w);
w.Show();
w.OnClosed(Reposition);
Add(w);
if (timeShow != null)
{
await Task.Run(async () =>
{
for (int i = 0; i < timeShow / 100; i++)
{
await Task.Delay(100);
if (w.IsClosed) break;
}
});
if (!w.IsClosed)
w.Close();
}
}
}
}