Forum Xamarin Xamarin.Forms

Stopwatch error

Hi. I have been trying to make a stopwatch now for the past few weeks, I feel like I'm pretty close I just need to figure out how to get it to display to the screen. Has anyone got any ideas? I would REALLY Appreciate any help. I will post my code to the bottom of the screen. Thanks again.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using System.Diagnostics;
using System.Threading;
using System.Runtime.InteropServices;
using System.Collections.Specialized;
using Windows.UI.Xaml;

namespace App3


public partial class MainPage : ContentPage

    private const string Format = "{0:00}:{1:00}:{2:00}.{3:00}";

    DispatcherTimer dt = new DispatcherTimer();
    Stopwatch stopWatch = new Stopwatch();
    string currentTime = string.Empty;

    public MainPage()

        Stopwatch stopWatch = new Stopwatch();
        // Get the elapsed time as a TimeSpan value.
        TimeSpan ts = stopWatch.Elapsed;

        // Format and display the TimeSpan value.
        string ClockTextBlock = String.Format(Format,
            ts.Hours, ts.Minutes, ts.Seconds,
            ts.Milliseconds / 10);
        Console.WriteLine("RunTime " + ClockTextBlock);


        dt.Tick += new EventHandler(dt_Tick);
        dt.Interval = new TimeSpan(0, 0, 0, 0, 1);

        void dt_Tick(object sender, EventArgs e)
            if (stopWatch.IsRunning)
                TimeSpan t = stopWatch.Elapsed;
                currentTime = String.Format("{0:00}:{1:00}:{2:00}",
                    ts.Hours, ts.Minutes, ts.Seconds);
                ClockTextBlock.ToString (currentTime);


    public String Display(Object sender, String ClockTextBlock)

        return ClockTextBlock + String.Format(Format);
    public void StartButton_Click(Object sender, Stopwatch stopwatch)

    public void StopButton_Click(Object sender, Stopwatch stopwatch)
    public void ResetButton_Click(Object sender, Stopwatch stopwatch)




  • JamesLaveryJamesLavery GBBeta, University ✭✭✭✭✭
    What is the actual problem you are having?
  • KeithnoloKeithnolo Member ✭✭

    Hi james, I just need to get the timer to display to the screen and actually display what's happening? any ideas?

Sign In or Register to comment.