2 using System.ComponentModel;
3 using System.Runtime.CompilerServices;
4 using System.Windows.Input;
5 using Tizen.NUI.Binding;
7 using System.Diagnostics;
9 namespace NUITizenGallery.ViewModels
11 public class TimerTest1ViewModel : INotifyPropertyChanged, IDisposable
13 private readonly Timer timer;
14 private readonly Stopwatch stopWatch = new Stopwatch();
15 private bool timerStarted;
16 private string hoursMinutesSeconds;
17 private string miliseconds;
18 private bool disposed = false;
20 public ICommand StartTimer
26 public ICommand StopTimer
32 public TimerTest1ViewModel()
35 timer = new Timer(100);
37 timer.Tick += OnTimerIntervalElapsed;
40 StartTimer = new Command(ExecuteStartTimer);
41 StopTimer = new Command(ExecuteStopTimer);
42 HoursMinutesSeconds = "00:00";
46 private bool OnTimerIntervalElapsed(object sender, Timer.TickEventArgs e)
48 var ts = stopWatch.Elapsed;
49 HoursMinutesSeconds = ts.Hours == 0 ?
50 string.Format("{0:00}:{1:00}", ts.Minutes, ts.Seconds) :
51 string.Format("{0:00}:{1:00}:{2:00}", ts.Hours, ts.Minutes, ts.Seconds);
53 Miliseconds = string.Format(".{0:00}", ts.Milliseconds / 10);
58 public bool TimerStarted
63 if (timerStarted != value)
66 RaisePropertyChagend();
71 public string HoursMinutesSeconds
73 get => hoursMinutesSeconds;
76 if (hoursMinutesSeconds != value)
78 hoursMinutesSeconds = value;
79 RaisePropertyChagend();
84 public string Miliseconds
89 if (miliseconds != value)
92 RaisePropertyChagend();
97 private void ExecuteStartTimer()
105 private void ExecuteStopTimer()
107 TimerStarted = false;
113 public event PropertyChangedEventHandler PropertyChanged;
115 private void RaisePropertyChagend([CallerMemberName] string propertyName = null)
117 PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
120 public void Dispose()
123 GC.SuppressFinalize(this);
126 protected virtual void Dispose(bool disposing)
132 timer.Tick -= OnTimerIntervalElapsed;