无法访问xaml.cs文件中的简单cs文件的静态方法

时间:2014-05-20 18:11:29

标签: class windows-phone-8 methods static

我正在为我的学期项目创建一个应用程序。在这个项目中,我有一个简单的类文件和一些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

public static class globalx     {         public static int n;         public static int s;         public static int m;         public static int q;         public static int c;         public static int f;         public static lane [] l = new lane [4];         公共静态双电视;         public static int tym;         public static int [] a = {0,0,0,0};         public static int [] t = new int [4];         public static string str =“asdf”;         public static int cdt; // countdowntime         public static int x;         public static DateTime begin;

    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;

    }

1 个答案:

答案 0 :(得分:0)

使用try catch对您的代码进行搜索,看看该消息是什么。

  try

    {
       // Your Code
    }

    catch (Exception ex)
    {

    Debug.writeline(ex.Message);

    }