These are my declarations and DispatcherTimer methods:
private DispatcherTimer DishTimer; private TimeSpan SpanTime; private void InitTimer() { DishTimer = new DispatcherTimer(); DishTimer.Interval = new TimeSpan(0, 0, 0, 1); DishTimer.Tick += TimerOnTick; } private void TimerOnTick(object sender, object o) { SpanTime = SpanTime.Add(DishTimer.Interval); Duration.DataContext = SpanTime; }
Here I call it:
private void CaptureButton_Click(object sender, RoutedEventArgs e) { if ((string) CaptureButton.Content == "Capture") { CaptureAudio(); InitTimer(); DishTimer.Start(); ProgressRing.IsActive = true; CaptureButton.Content = "Stop"; } else { StopCapture(); DishTimer.Stop(); ProgressRing.IsActive = false; CaptureButton.Content = "Capture"; } }
and here is my xaml code for showing the timer:
<TextBlock Name="Duration" Text="{Binding}" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="24"></TextBlock>
I am making a voice recording application, and I want to show a timer every time the user clicks the capture button. My problem here is that I cannot reset it
kaza.ma
source share