C # xaml how to set the global object for all pages in the application

advertisements

I have a ten pages and i want to define this object:

Stopwatch sw = new Stopwatch();

for all the pages in the app, not to write this in each page.


Do you need to have many instances of Stopwatch or one instance for all application. In last case you need add this code to App.xaml.cs:

    private static Stopwatch _stopwatch = null;
    public static Stopwatch  Stopwatch
    {
        get
        {
            if (_stopwatch == null)
                _stopwatch = new Stopwatch();

            return _stopwatch;
        }
        set { }
    }

Here I have created private instance of the class and method to get this instance.