-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathNotificationWindow.axaml.cs
More file actions
64 lines (55 loc) · 1.82 KB
/
NotificationWindow.axaml.cs
File metadata and controls
64 lines (55 loc) · 1.82 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
using Avalonia;
using Avalonia.Controls;
using Avalonia.Threading;
namespace ShowWrite
{
public partial class NotificationWindow : Window
{
private System.Timers.Timer? _closeTimer;
public NotificationWindow()
{
InitializeComponent();
}
public void ShowNotification(string message, int durationMs = 3000)
{
MessageText.Text = message;
Dispatcher.UIThread.Post(() =>
{
var mainWindow = App.MainWindow;
if (mainWindow != null)
{
var workingArea = mainWindow.Screens.Primary.WorkingArea;
var width = workingArea.Width;
var height = workingArea.Height;
Show(mainWindow);
Position = new PixelPoint(
(int)(width - Width - 20),
(int)(height - Height - 20)
);
_closeTimer?.Dispose();
_closeTimer = new System.Timers.Timer(durationMs);
_closeTimer.Elapsed += (s, e) =>
{
Dispatcher.UIThread.Post(() =>
{
Close();
});
_closeTimer?.Dispose();
};
_closeTimer.AutoReset = false;
_closeTimer.Start();
}
});
}
private void CloseButton_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e)
{
_closeTimer?.Dispose();
Close();
}
protected override void OnClosing(WindowClosingEventArgs e)
{
_closeTimer?.Dispose();
base.OnClosing(e);
}
}
}