using System; using System.Diagnostics.Eventing.Reader; using System.Globalization; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Windows.Threading; using Microsoft.Extensions.Configuration; namespace CountDown; /// /// Interaction logic for MainWindow.xaml /// public partial class MainWindow : Window { public DateTime EventDate { get; set; } private DispatcherTimer _timer; readonly CultureInfo _enUS = new ("en-US"); public TimeSpan Counter { get { return (TimeSpan)GetValue(CounterProperty); } set { SetValue(CounterProperty, value); } } public static readonly DependencyProperty CounterProperty = DependencyProperty.Register(nameof(Counter), typeof(TimeSpan), typeof(MainWindow), new PropertyMetadata(new TimeSpan(0, 0, 0))); public MainWindow() { InitializeComponent(); DataContext = this; var dateString = App.Config?.GetChildren().FirstOrDefault(c => c.Key == "EventDate")?.Value ?? "2025-06-30 23:59:59"; if (DateTime.TryParseExact(dateString, "yyyy-MM-dd HH:mm:s", _enUS, DateTimeStyles.None, out DateTime dateValue)) { EventDate = dateValue; } else { EventDate = new DateTime(2025, 06, 30, 23, 59, 59, DateTimeKind.Local); } Left = System.Windows.SystemParameters.PrimaryScreenWidth - Width - 20; Top = System.Windows.SystemParameters.PrimaryScreenHeight - Height - 100; Topmost = true; BitmapImage image = new (new Uri("./background.png", UriKind.Relative)); ImageBrush fond = new (image); this.Background = fond; _timer = new(); _timer.Interval = new TimeSpan(0, 0, 1); _timer.Tick += TimerTicked; _timer.Start(); } private void SetTime() { Counter = EventDate - DateTime.Now; } private void TimerTicked(object? sender, EventArgs e) { SetTime(); } }