-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotificationWindow.axaml.cs
More file actions
39 lines (33 loc) · 1.04 KB
/
Copy pathNotificationWindow.axaml.cs
File metadata and controls
39 lines (33 loc) · 1.04 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
using System;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Threading;
namespace BrainFuel;
/// <summary>A small transient popup shown at the bottom-right of the screen.</summary>
public partial class NotificationWindow : Window
{
public NotificationWindow()
{
InitializeComponent();
}
public void ShowNotification(string title, string message)
{
TitleText.Text = title;
MessageText.Text = message;
PositionBottomRight();
Show();
var timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(6) };
timer.Tick += (_, _) => { timer.Stop(); Close(); };
timer.Start();
}
private void PositionBottomRight()
{
var screen = Screens.Primary;
if (screen == null) return;
double scale = RenderScaling > 0 ? RenderScaling : 1;
int devW = (int)(Width * scale);
int devH = (int)(Height * scale);
var wa = screen.WorkingArea;
Position = new PixelPoint(wa.Right - devW - 16, wa.Bottom - devH - 16);
}
}