Code: Select all
<StackPanel Orientation="Horizontal">
<Button Content="Click to Start" Background="#FFE44D26" Click="ButtonToStartTimer_Click"/>
<Button Content="Click to Stop" Background="#FFE44D26" Click="ButtonToStopTimer_Click"/>
<TextBlock Text="0" x:Name="CounterTextBlock" FontSize="26"/>
</StackPanel>
Code: Select all
_dispatcherTimer = new DispatcherTimer() { Interval = new TimeSpan(0, 0, 0, 0, 100) };
_dispatcherTimer.Tick += OnTick;
void ButtonToStartTimer_Click(object s, RoutedEventArgs e)
{
_dispatcherTimer.Start();
}
void ButtonToStopTimer_Click(object s, RoutedEventArgs e)
{
_dispatcherTimer.Stop();
}
void OnTick(object s, object e)
{
CounterTextBlock.Text = (int.Parse(CounterTextBlock.Text) + 1).ToString();
}
Users browsing this forum: No registered users and 6 guests