-1

I´ve two classes. Thats the first one:

namespace Working_Times.Klassen
{
    class calcHours
    {
        //Right here i need the value of startTime from MainPage
    }
}

The 2nd one is called MainPage

I´ve already tried in calcHours

MainPage mP = new MainPage(); 
mP.startTime = 3; //for example, if startTime was an integer
   //it says: mP.startTime not available in the current context 
              startTime not available in the current context 

Thanks a lot :) A lot of people have been answering me, the problem would be the acess. In my case, i guess, that´s not the problem. I´ve already tried to change every variable to public. Still doesen´t run. SF

Stephan1403
  • 17
  • 2
  • 10
  • Nobody ever reads exception messages :( _"mP.startTime not available in the current context "_ means that the field called `startTime` of `mP` object is not available in context of your calling method. – vasily.sib Jul 22 '20 at 11:47
  • 1
    there must be a field/variable/property in `MainPage` class named as `startTime` and it should be `public`. like this `public int startTime;` – Hammas Jul 22 '20 at 11:51
  • Make sure the property is Public. – jdweng Jul 22 '20 at 11:51
  • The question [Public Fields versus Automatic Properties](https://stackoverflow.com/questions/1180860/public-fields-versus-automatic-properties) could have an answer you are looking for – bartolo-otrit Jul 22 '20 at 12:08

1 Answers1

1

startTime not available in the current context

The problem is that you have not declare startTime property in MainPage class. You need add startTime like the following.

public class MainPage : Page
{
    public int StartTime { get; set; }

    public MainPage()
    {
       
    }
}

How to get acess to variables from other classes in UWP

You have many ways to do that, fist is declare a property for the like and access property with an instance like above, other is declare static variable and access with class name.

public class MainPage : Page
{    
    public MainPage()
    {
       
    }
    public static int EndTime;

}

Access

 MainPage.EndTime = 4;
Nico Zhu
  • 32,367
  • 2
  • 15
  • 36