Class can';t访问xaml.cs文件中简单cs文件的静态方法

Class can';t访问xaml.cs文件中简单cs文件的静态方法,class,windows-phone-8,methods,static,Class,Windows Phone 8,Methods,Static,我正在为我的学期项目创建一个应用程序。在这个项目中,我有一个简单的类文件和几个xaml页面。在一个xaml页面中,代码检查字符串的值,并根据该值运行倒计时。如果string的值等于某个字符串,那么它应该从更改string值的简单类调用一个方法,然后它应该导航到下一个xaml页面 当我调用函数时,应用程序中断。没有错误或任何东西,它只是中断。我不知道为什么。我在其他xaml文件中调用了同一类文件的其他函数,它们工作得很好,但在这里我遇到了麻烦。我想这和定时器有关 xaml.cs: namespac

我正在为我的学期项目创建一个应用程序。在这个项目中,我有一个简单的类文件和几个xaml页面。在一个xaml页面中,代码检查字符串的值,并根据该值运行倒计时。如果string的值等于某个字符串,那么它应该从更改string值的简单类调用一个方法,然后它应该导航到下一个xaml页面

当我调用函数时,应用程序中断。没有错误或任何东西,它只是中断。我不知道为什么。我在其他xaml文件中调用了同一类文件的其他函数,它们工作得很好,但在这里我遇到了麻烦。我想这和定时器有关

xaml.cs:

namespace TrafficGuru
{
    public partial class Page2 : PhoneApplicationPage
    {
        DispatcherTimer countDownTimer;
        int check;

        public Page2()
        {
            InitializeComponent();
            tbl.Text = global.str;
            if (global.str == "YOUR LIGHT IS ON FOR : ")
            {
                check = 0;
            }
            if (global.str == "YOUR LIGHT WILL BE ON IN:")
            {
                check = 1;
            }
            if (global.str == "YOUR LIGHT WILL NOT BE ON FOR UNTIL ATLEAST " + global.x * 15 + " MORE SECS.YOU WILL GET AN UPDATE IN:")
            {
                check = 2;
            }
            countDownTimer = new DispatcherTimer();
            countDownTimer.Interval = new TimeSpan(0, 0, 0, 1);
            countDownTimer.Tick += new EventHandler(countDownTimerEvent);
            countDownTimer.Start();




            test.Content = "" + "seconds remaining";
        }
        int count = global.cdt;

        void test_Click(object sender, EventArgs e) { }
        void countDownTimerEvent(object sender, EventArgs e)
        {
            test.Content = count + " Seconds";


            if (count > 0)
            {
                count--;
            }
            else if (count == 0)
            {
              if (check == 0)
                {
                    test.Content = "STOP!!";


                }
                else if (check == 1)
                {
                    test.Content = "GO!!!";


                }

                if(check==2)
                {
                  string x= global.rego();//the method i m trying to call its public and static





                    NavigationService.Navigate(new Uri("/Page3.xaml", UriKind.RelativeOrAbsolute));*/


                }
               }
            }



    }

}
globalx类代码::

if (x == 1)
                    {
                        str = "YOUR LIGHT WILL BE ON IN:";
                    }

                    cdt = x*15;

                    l[m].resetcount();
                    a[m] = 0;
                    l[m].setlight("RED");
                    c = 9;

                }

            if (l[0].getcount() == 0 || s > 0)
            {
                l[0].Createcar();
            }
            a[0] += l[0].getcount();
            t[0] = l[0].gettime();
            if (l[1].getcount() == 0 || s > 0)
            {
                l[1].Createcar();
            }
            a[1] += l[1].getcount();
            t[1] = l[1].gettime();
            if (l[2].getcount() == 0 || s > 0)
            {
                l[2].Createcar();
            }
            a[2] = l[2].getcount();
            t[2] = l[2].gettime();

            if (l[3].getcount() == 0 || s > 0)
            {
                l[3].Createcar();
            }
            a[3] += l[3].getcount();
            t[3] = l[3].gettime();
            s++;
            if (s % 2 != 0)
            {
                var now1 = DateTime.Now;
                tv = (now1 - begin).TotalMilliseconds;
                tym = Convert.ToInt32(tv);
                int[] pkl = { 0, 0 };
                maxi(a, t, s, tym, ref pkl);
                m = pkl[0];
            }
            else
            {
                var now1 = DateTime.Now;
                tv = (now1 - begin).TotalMilliseconds;
                tym = Convert.ToInt32(tv);
                int[] pkj = { 0, 0 };
                maxi(a, t, s, tym, ref pkj);
                q = pkj[0];
            }
            return str;
        }
用GO和REGO完成全局类

公共静态类globalx { 公共静态int n; 公共静态INTS; 公共静态INTM; 公共静态int-q; 公共静态INTC; 公共静态INTF; 公共静态车道[]l=新车道[4]; 公共静电双电视; 公共静态int tym; 公共静态int[]a={0,0,0,0}; 公共静态int[]t=新int[4]; 公共静态字符串str=“asdf”; 公共静态int cdt;//countdown 公共静态int x; 公共静态日期开始时间

    public static void start()
    {

        begin = DateTime.Now;

        for (int i = 0; i < 4; i++)
        { l[i] = new lane(); }



        var now = DateTime.Now;
        tv = (now - begin).TotalMilliseconds;
        tym = Convert.ToInt32(tv);
        l[0].Createcar();
        a[0] += l[0].getcount();
        t[0] = l[0].gettime();

        l[1].Createcar();
        a[1] += l[1].getcount();
        t[1] = l[1].gettime();

        l[2].Createcar();
        a[2] += l[2].getcount();
        t[2] = l[2].gettime();

        l[3].Createcar();
        a[3] += l[3].getcount();
        t[3] = l[3].gettime();
        now = DateTime.Now;
        tv = (now - begin).TotalMilliseconds;
        tym = Convert.ToInt32(tv);
        int[] r = { 88, 99 };
        maxi(a, t, s, tym, ref r);
        m = r[0];
        q = r[1];
        c = 0;
        f = 9;
    }
    public static string go()
   {

            l[m].setlight("GREEN");
            var now = DateTime.Now;
            tv = (now - begin).TotalMilliseconds;
            tym = Convert.ToInt32(tv);
            l[m].settime(tym);
            if (n == m + 1)
            {
                c = 0;
                str = "YOUR LIGHT IS ON FOR : ";
                cdt = 15;

                l[m].resetcount();
                a[m] = 0;
                l[m].setlight("RED");

            }
            if (n == q + 1)
            {
                c = 9;
                str = "YOUR LIGHT WILL BE ON IN:";
                cdt = 15;
                                    l[m].resetcount();
                a[m] = 0;
                l[m].setlight("RED");
            }
            if (n != m + 1 && n != q + 1)
            {
                x = m + 1 - n;
                if (x < 0)
                {
                    x = 0 - x;
                }

                str = "YOUR LIGHT WILL NOT BE ON FOR UNTIL ATLEAST " + x * 15 + " MORE SECS.YOU WILL GET AN UPDATE IN:";
                if (x == 1)
                {
                    str = "YOUR LIGHT WILL BE ON IN:";
                }

                cdt = x*15;
                a[m] = 0;
                l[m].setlight("RED");
                c = 9;

            }

        if (l[0].getcount() == 0 || s > 0)
        {
            l[0].Createcar();
        }
        a[0] += l[0].getcount();
        t[0] = l[0].gettime();
        if (l[1].getcount() == 0 || s > 0)
        {
            l[1].Createcar();
        }
        a[1] += l[1].getcount();
        t[1] = l[1].gettime();
        if (l[2].getcount() == 0 || s > 0)
        {
            l[2].Createcar();
        }
        a[2] = l[2].getcount();
        t[2] = l[2].gettime();

        if (l[3].getcount() == 0 || s > 0)
        {
            l[3].Createcar();
        }
        a[3] += l[3].getcount();
        t[3] = l[3].gettime();
        s++;
        if (s % 2 != 0)
        {
            var now1 = DateTime.Now;
            tv = (now1 - begin).TotalMilliseconds;
            tym = Convert.ToInt32(tv);
            int[] pkl = { 0, 0 };
            maxi(a, t, s, tym, ref pkl);
            m = pkl[0];
        }
        else
        {
            var now1 = DateTime.Now;
            tv = (now1 - begin).TotalMilliseconds;
            tym = Convert.ToInt32(tv);
            int[] pkj = { 0, 0 };
            maxi(a, t, s, tym, ref pkj);
            q = pkj[0];
        }
        return str;
    }
    public static string rego()

    {

        {

            l[q].setlight("GREEN");
            var now = DateTime.Now;
            tv = (now - begin).TotalMilliseconds;
            tym = Convert.ToInt32(tv);
            l[q].settime(tym);

            if (n == q + 1)
            {
                f = 0;
                str = "YOUR LIGHT IS ON FOR : ";
                cdt=15;
            }
            if (n == m + 1)
            {

                str = "YOUR LIGHT WILL BE ON IN:";
                cdt=15;
                l[q].resetcount();
                a[q] = 0;
                l[q].setlight("RED");
                f = 9;
            }
            if (n != m + 1 && n != q + 1)
            {
                x = m + 1 - n;
                if (x < 0)
                {
                    x = 0 - x;
                }

                str = "YOUR LIGHT WILL NOT BE ON FOR UNTIL ATLEAST " + x * 15 + " MORE SECS.YOU WILL GET AN UPDATE IN:";
                if (x == 1)
                {
                    str = "YOUR LIGHT WILL BE ON IN:";
                }
                cdt = x * 15;

                a[q] = 0;
                l[q].setlight("RED");
                f = 9;
            }
        }

        if (l[0].getcount() == 0 || s > 0)
        {
            l[0].Createcar();
        }
        a[0] += l[0].getcount();
        t[0] = l[0].gettime();
        if (l[1].getcount() == 0 || s > 0)
        {
            l[1].Createcar();
        }
        a[1] += l[1].getcount();
        t[1] = l[1].gettime();
        if (l[2].getcount() == 0 || s > 0)
        {
            l[2].Createcar();
        }
        a[2] = l[2].getcount();
        t[2] = l[2].gettime();

        if (l[3].getcount() == 0 || s > 0)
        {
            l[3].Createcar();
        }
        a[3] += l[3].getcount();
        t[3] = l[3].gettime();
        s++;
        if (s % 2 != 0)
        {
            var now = DateTime.Now;
            tv = (now - begin).TotalMilliseconds;
            tym = Convert.ToInt32(tv);
            int[] pkl = { 0, 0 };
            maxi(a, t, s, tym, ref pkl);
            m = pkl[0];
        }
        else
        {
            var now = DateTime.Now;
            tv = (now - begin).TotalMilliseconds;
            tym = Convert.ToInt32(tv);
            int[] pkj = { 0, 0 };
            maxi(a, t, s, tym, ref pkj);
            q = pkj[0];
        }
        return str;

    }
publicstaticvoidstart()
{
begin=DateTime.Now;
对于(int i=0;i<4;i++)
{l[i]=新车道();}
var now=DateTime.now;
tv=(现在开始).totalms;
tym=转换为32(电视);
l[0].Createcar();
a[0]+=l[0].getcount();
t[0]=l[0].gettime();
l[1].Createcar();
a[1]+=l[1].getcount();
t[1]=l[1].gettime();
l[2].Createcar();
a[2]+=l[2].getcount();
t[2]=l[2].gettime();
l[3].Createcar();
a[3]+=l[3].getcount();
t[3]=l[3].gettime();
现在=日期时间。现在;
tv=(现在开始).totalms;
tym=转换为32(电视);
int[]r={88,99};
最大值(a、t、s、tym、参考r);
m=r[0];
q=r[1];
c=0;
f=9;
}
公共静态字符串go()
{
l[m]。背景光(“绿色”);
var now=DateTime.now;
tv=(现在开始).totalms;
tym=转换为32(电视);
l[m].设定时间(tym);
如果(n==m+1)
{
c=0;
str=“您的指示灯为:”;
cdt=15;
l[m].resetcount();
a[m]=0;
l[m]。背景光(“红色”);
}
如果(n==q+1)
{
c=9;
str=“您的灯将在:”;
cdt=15;
l[m].resetcount();
a[m]=0;
l[m]。背景光(“红色”);
}
如果(n!=m+1&&n!=q+1)
{
x=m+1-n;
if(x<0)
{
x=0-x;
}
str=“至少在”+x*15+“秒后,您的指示灯才会亮起。您将在:”;
如果(x==1)
{
str=“您的灯将在:”;
}
cdt=x*15;
a[m]=0;
l[m]。背景光(“红色”);
c=9;
}
如果(l[0].getcount()==0 | | s>0)
{
l[0].Createcar();
}
a[0]+=l[0].getcount();
t[0]=l[0].gettime();
如果(l[1].getcount()==0 | | s>0)
{
l[1].Createcar();
}
a[1]+=l[1].getcount();
t[1]=l[1].gettime();
如果(l[2].getcount()==0 | | s>0)
{
l[2].Createcar();
}
a[2]=l[2].getcount();
t[2]=l[2].gettime();
如果(l[3].getcount()==0 | | s>0)
{
l[3].Createcar();
}
a[3]+=l[3].getcount();
t[3]=l[3].gettime();
s++;
如果(s%2!=0)
{
var now1=DateTime.Now;
tv=(now1-begin).totalms;
tym=转换为32(电视);
int[]pkl={0,0};
最大值(a、t、s、tym、参考pkl);
m=pkl[0];
}
其他的
{
var now1=DateTime.Now;
tv=(now1-begin).totalms;
tym=转换为32(电视);
int[]pkj={0,0};
maxi(a,t,s,tym,ref-pkj);
q=pkj[0];
}
返回str;
}
公共静态字符串rego()
{
{
l[q].背景光(“绿色”);
var now=DateTime.now;
tv=(现在开始).totalms;
tym=转换为32(电视);
l[q].设定时间(tym);
如果(n==q+1)
{
f=0;
str=“您的指示灯为:”;
cdt=15;
}
如果(n==m+1)
{
str=“您的灯将在:”;
cdt=15;
l[q].resetcount();
a[q]=0;
l[q]。背景光(“红色”);
f=9;
}
如果(n!=m+1&&n!=q+1)
{
x=m+1-n;
if(x<0)
{
x=0-x;
}
str=“至少在”+x*15+“秒后,您的指示灯才会亮起。您将在:”;
如果(x==1)
{
str=“您的灯将在:”;
}
cdt=x*15;
a[q]=0;
l[q]。背景光(“红色”);
f=9;
}
}
if(l[0]。
  try

    {
       // Your Code
    }

    catch (Exception ex)
    {

    Debug.writeline(ex.Message);

    }