123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- namespace HistoryView.Controls.Basics;
- public partial class TimerWatch : UserControl
- {
- public TimerWatch()
- {
- InitializeComponent();
- _timer.Elapsed += new System.Timers.ElapsedEventHandler(OnTmrTrg);
- _timer.Interval = 1000;
- _timer.AutoReset = true;
- _timer.Enabled = true;
- }
- private readonly System.Timers.Timer _timer = new();
- private void OnTmrTrg(object? sender, System.Timers.ElapsedEventArgs e)
- {
- try
- {
- App.Current?.Dispatcher?.Invoke(() =>
- {
- this.Date.Text = DateTime.Now.ToString("yyyy/MM/dd");
- this.Time.Text = DateTime.Now.ToString("HH:mm:ss");
- });
- }
- catch
- {
- }
- }
- public Orientation Orientation
- {
- get { return (Orientation)GetValue(OrientationProperty); }
- set { SetValue(OrientationProperty, value); }
- }
- public static readonly DependencyProperty OrientationProperty =
- DependencyProperty.Register("Orientation", typeof(Orientation), typeof(TimerWatch), new PropertyMetadata(default));
- public SolidColorBrush TextBrush
- {
- get { return (SolidColorBrush)GetValue(TextBrushProperty); }
- set { SetValue(TextBrushProperty, value); }
- }
- // Using a DependencyProperty as the backing store for TextBrush. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty TextBrushProperty =
- DependencyProperty.Register("TextBrush", typeof(SolidColorBrush), typeof(TimerWatch), new PropertyMetadata(new SolidColorBrush()));
- }
|