That’s my code inside my MainPage.xaml.cs
public MainPage()
{
InitializeComponent();
DispatcherTimer dt = new DispatcherTimer();
dt.Interval = new TimeSpan(0, 0, 0, 0, 1000); // 1 Second
dt.Tick += new EventHandler(dtTick);
}
Now after the MainPage Constractor I have and the dtTick EventHandler to DO SOMETHING and an EventHandler for a start button to make the Timer works
void dtTick(object sender, EventArgs e)
{
var time = DateTime.Parse(theTimer.Text);
time = time.AddSeconds(1);
theTimer.Text = time.ToString("HH:mm:ss");
}
private void startButton_Click(object sender, RoutedEventArgs e)
{
dt.Start();
}
So My question is how how can I make dt.Start(); works cause it’s a method called on an object that is located in my MainPage().
In your code behind file expose the Timer as a public/protected or private member or field.