| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- using System;
- using System.Diagnostics;
- using System.Diagnostics.Eventing.Reader;
- using System.Globalization;
- using System.Reflection;
- 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;
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- 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();
- }
- private void DoClick(object sender, MouseButtonEventArgs e)
- {
- var path = System.IO.Path.GetDirectoryName(new System.Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);
- if (!string.IsNullOrEmpty(path))
- {
- Process.Start("explorer.exe", path);
- }
- }
- }
|