-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
55 lines (47 loc) · 1.45 KB
/
MainWindow.xaml.cs
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
using System;
using System.Windows;
using System.Windows.Threading;
namespace AlarmApp
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private readonly MainWindowViewModel viewModel;
public MainWindow()
{
viewModel = new MainWindowViewModel();
InitializeComponent();
DataContext = viewModel;
DispatcherTimer timer = new();
timer.Tick += Timer_Tick;
timer.Interval = new TimeSpan(0, 0, 1);
timer.Start();
}
private void Timer_Tick(object? sender, EventArgs e)
{
try
{
foreach (AlarmViewModel alarm in viewModel.Alarms)
{
alarm.Date = alarm.Date.Subtract(TimeSpan.FromSeconds(1));
if (alarm.Date.CompareTo(DateTime.Now) == 0 || alarm.Date.CompareTo(DateTime.Now) < 0)
{
viewModel.Alarms.Remove(alarm);
var alarmWindow = new AlarmWindow();
alarmWindow.Show();
}
}
}
catch (Exception)
{
}
}
private void AddAlarmButton_Click(object sender, RoutedEventArgs e)
{
AddAlarm window = new(viewModel);
window.ShowDialog();
}
}
}